Submission #479169

# Submission time Handle Problem Language Result Execution time Memory
479169 2021-10-10T14:04:51 Z Neos Zapina (COCI20_zapina) C++14
0 / 110
2 ms 844 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
 
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define numBit(x) __builtin_popcount(x)
#define lb lower_bound
#define ub upper_bound
#define ar array
#define endl '\n'
 
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
 
const int N = 350 + 7;
const ll inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int n, C[N][N], dp[2][N][N];
bool avail[2][N][N];

int add(int x, int y) {
  x += y; if (x >= MOD) x -= MOD;
  return x;
}

int mul(int x, int y) {
  return 1LL * x * y % MOD;
}

int fexp(int x, int y) {
  int ans = 1;
  while (y > 0) {
    if (y & 1) ans = mul(ans, x);
    x = mul(x, x);
    y >>= 1;
  }
  return ans;
}

int DP(bool happy, int n, int k) {
  if (n == 0) return happy && (k == 0);
  if (avail[happy][n][k]) return dp[happy][n][k];
  avail[happy][n][k] = 1;

  int ans = 0;
  forw(i, 0, k + 1)
    ans = add(ans, mul(C[k][i], DP(happy | (i == n), n - 1, k - i)));
  return dp[happy][n][k] = ans;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen(task".inp", "r", stdin);
  freopen(task".out", "w", stdout);
#endif
  fastIO;

  forw(i, 0, N) forw(j, 0, min(1ll * N, i) + 1)
    if (j == 0 || j == i) C[i][j] = 1;
    else C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);

  cin >> n;
  cout << DP(0, n, n) << endl; // happy, indx, remaining task
}

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:72:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zapina.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -