Submission #1307307


Source Code Expand

#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 405;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> pl;
typedef pair<ll, ll> pll;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A[NMAX],B[NMAX],C,D,E;
ll table[NMAX][NMAX] = {};
ll dp[NMAX][NMAX] = {};

string S;
vec v;

ll ans = 0;

inline ll f(int x_i, int a){
  if(x_i == 1) return a + 1;
  else return (pow(x_i, a + 1) - 1) / (x_i - 1);
}

void solve(){
  // main algorithm
  // fill table
  for (int i = 0; i < N; ++i)
  {
    table[i][0] = 1;
    ll pwr = 1;
    for (int a = 1; a < NMAX; ++a)
    {
      pwr = pwr * A[i] % MOD;
      // table[i][a] = (pwr + table[i][a-1]) % MOD;
      table[i][a] = pwr;
    }
  }
  // dp
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i)
  {
    for (int c = 0; c <= C; ++c)
    {
      if (!dp[i][c]) continue;
      for (int a = 0; c + a <= C; ++a)
      {
        dp[i+1][c+a] = (dp[i+1][c+a] + dp[i][c] * table[i][a]) % MOD;
      }
    }
  }
  ans = dp[N][C];
}
void debug(){
  // output debug information
  cout << "table:\n";
  for (int i = 0; i < N; ++i)
  {
    for (int a = 0; a < C+1; ++a)
    {
      cout << table[i][a] << " ";
    }
    cout << endl;
   }
  cout << "dp:\n";
  for (int i = 0; i <= N; ++i)
  {
    for (int a = 0; a < C+1; ++a)
    {
      cout << dp[i][a] << " ";
    }
    cout << endl;
  }
}
void answer(){
  // output answer
  printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  scanf("%lld%lld", &N,&C);
  for (int i = 0; i < N; ++i)
  {
    scanf("%lld", &A[i]);
  }
  for (int i = 0; i < N; ++i)
  {
    scanf("%lld", &B[i]);
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Submission Info

Submission Time
Task E - Children and Candies
User anekawa
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3943 Byte
Status WA
Exec Time 111 ms
Memory 5888 KB

Compile Error

./Main.cpp: In function ‘int main(int, const char**)’:
./Main.cpp:178:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &N,&C);
                           ^
./Main.cpp:181:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &A[i]);
                         ^
./Main.cpp:185:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &B[i]);
                         ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 0 / 400 0 / 400
Status
WA × 5
WA × 12
WA × 30
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt
Subtask 0_001, 0_003, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 2_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt
Case Name Status Exec Time Memory
0_000.txt WA 1 ms 256 KB
0_001.txt WA 1 ms 256 KB
0_002.txt WA 1 ms 256 KB
0_003.txt WA 1 ms 256 KB
0_004.txt WA 1 ms 256 KB
1_005.txt WA 1 ms 256 KB
1_006.txt WA 1 ms 256 KB
1_007.txt WA 1 ms 256 KB
1_008.txt WA 1 ms 256 KB
1_009.txt WA 1 ms 256 KB
1_010.txt WA 1 ms 256 KB
1_011.txt WA 5 ms 2816 KB
1_012.txt WA 5 ms 2816 KB
1_013.txt WA 5 ms 2816 KB
1_014.txt WA 108 ms 4608 KB
1_015.txt WA 111 ms 5888 KB
1_016.txt WA 110 ms 5888 KB
2_017.txt WA 1 ms 256 KB
2_018.txt WA 1 ms 256 KB
2_019.txt WA 1 ms 256 KB
2_020.txt WA 1 ms 256 KB
2_021.txt WA 5 ms 2816 KB
2_022.txt WA 5 ms 2816 KB
2_023.txt WA 108 ms 4608 KB
2_024.txt WA 110 ms 5888 KB
2_025.txt WA 28 ms 3968 KB
2_026.txt WA 5 ms 2432 KB
2_027.txt WA 90 ms 5120 KB
2_028.txt WA 5 ms 1152 KB
2_029.txt WA 2 ms 512 KB