Submission #479171

# Submission time Handle Problem Language Result Execution time Memory
479171 2021-10-10T14:05:11 Z Neos Zapina (COCI20_zapina) C++14
110 / 110
400 ms 2116 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() {
  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
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 816 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 816 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 872 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 816 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 2 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 872 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 844 KB Output is correct
17 Correct 192 ms 1680 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 42 ms 1356 KB Output is correct
20 Correct 3 ms 844 KB Output is correct
21 Correct 288 ms 1944 KB Output is correct
22 Correct 26 ms 1284 KB Output is correct
23 Correct 6 ms 972 KB Output is correct
24 Correct 84 ms 1428 KB Output is correct
25 Correct 34 ms 1364 KB Output is correct
26 Correct 76 ms 1500 KB Output is correct
27 Correct 370 ms 1944 KB Output is correct
28 Correct 368 ms 2016 KB Output is correct
29 Correct 373 ms 1936 KB Output is correct
30 Correct 380 ms 1988 KB Output is correct
31 Correct 389 ms 2040 KB Output is correct
32 Correct 400 ms 2052 KB Output is correct
33 Correct 384 ms 2004 KB Output is correct
34 Correct 388 ms 1948 KB Output is correct
35 Correct 367 ms 1952 KB Output is correct
36 Correct 384 ms 1980 KB Output is correct
37 Correct 374 ms 2116 KB Output is correct