# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114270 | 2024-11-18T13:21:45 Z | ljtunas | Zapina (COCI20_zapina) | C++14 | 210 ms | 3584 KB |
#include <bits/stdc++.h> using namespace std; #define db double #define pb push_back #define ll long long #define int long long #define ii pair<int, int> #define fi first #define se second #define vi vector <int> #define vii vector<ii> #define sqrt sqrtl #define FORV(v, H) for(auto &v: H) #define FOR(i, a, b) for(int i=a;i<=b;++i) #define FORD(i, a, b) for(int i=a;i>=b;--i) #define BIT(mask, i) ((mask >> i) & 1LL) #define ONBIT(mask, i) (mask bitor (1LL << i)) #define cnt_BIT(i) __builtin_popcountll(i) #define task "zapina" const int MAXN = 350 + 10; const int oo = 1e18 + 8; const int MOD = 1e9 + 7; int N; int dp[MAXN][MAXN][2]; int GT[MAXN], CKN[MAXN][MAXN]; int Pow(int a, int n) { if (n == 0) return 1; int h = Pow(a, n / 2); h = (h * h) % MOD; if (n & 1) return (a * h) % MOD; return h; } int Ckn(int k, int n) { if (k > n) return 0; int MAU = (GT[n - k] * GT[k]) % MOD; int TU = GT[n]; return (TU * Pow(MAU, MOD - 2)) % MOD; } int solve(int i, int cnt, bool ok) { if (i > N) { if (cnt == 0) return ok; return 0; } if (~dp[i][cnt][ok]) return dp[i][cnt][ok]; int cur = 0; FOR(j, 0, cnt) { if (j == i) cur = (cur + solve(i + 1, cnt - j, 1) * CKN[j][cnt]) % MOD; else cur = (cur + solve(i + 1, cnt - j, ok) * CKN[j][cnt]) % MOD; } return dp[i][cnt][ok] = cur; } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } GT[0] = 1; FOR(i, 1, MAXN - 5) GT[i] = (GT[i - 1] * i) % MOD; FOR(i, 0, MAXN) { FOR(j, 0, MAXN) CKN[i][j] = Ckn(i, j); } cin >> N; memset(dp, -1, sizeof(dp)); cout << solve(1, N, 0); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 3360 KB | Output is correct |
2 | Correct | 14 ms | 3400 KB | Output is correct |
3 | Correct | 14 ms | 3456 KB | Output is correct |
4 | Correct | 14 ms | 3408 KB | Output is correct |
5 | Correct | 14 ms | 3408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 3360 KB | Output is correct |
2 | Correct | 14 ms | 3400 KB | Output is correct |
3 | Correct | 14 ms | 3456 KB | Output is correct |
4 | Correct | 14 ms | 3408 KB | Output is correct |
5 | Correct | 14 ms | 3408 KB | Output is correct |
6 | Correct | 14 ms | 3408 KB | Output is correct |
7 | Correct | 14 ms | 3408 KB | Output is correct |
8 | Correct | 14 ms | 3572 KB | Output is correct |
9 | Correct | 14 ms | 3456 KB | Output is correct |
10 | Correct | 14 ms | 3408 KB | Output is correct |
11 | Correct | 15 ms | 3456 KB | Output is correct |
12 | Correct | 15 ms | 3408 KB | Output is correct |
13 | Correct | 14 ms | 3460 KB | Output is correct |
14 | Correct | 14 ms | 3408 KB | Output is correct |
15 | Correct | 14 ms | 3408 KB | Output is correct |
16 | Correct | 16 ms | 3408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 3360 KB | Output is correct |
2 | Correct | 14 ms | 3400 KB | Output is correct |
3 | Correct | 14 ms | 3456 KB | Output is correct |
4 | Correct | 14 ms | 3408 KB | Output is correct |
5 | Correct | 14 ms | 3408 KB | Output is correct |
6 | Correct | 14 ms | 3408 KB | Output is correct |
7 | Correct | 14 ms | 3408 KB | Output is correct |
8 | Correct | 14 ms | 3572 KB | Output is correct |
9 | Correct | 14 ms | 3456 KB | Output is correct |
10 | Correct | 14 ms | 3408 KB | Output is correct |
11 | Correct | 15 ms | 3456 KB | Output is correct |
12 | Correct | 15 ms | 3408 KB | Output is correct |
13 | Correct | 14 ms | 3460 KB | Output is correct |
14 | Correct | 14 ms | 3408 KB | Output is correct |
15 | Correct | 14 ms | 3408 KB | Output is correct |
16 | Correct | 16 ms | 3408 KB | Output is correct |
17 | Correct | 106 ms | 3468 KB | Output is correct |
18 | Correct | 16 ms | 3408 KB | Output is correct |
19 | Correct | 34 ms | 3408 KB | Output is correct |
20 | Correct | 15 ms | 3576 KB | Output is correct |
21 | Correct | 138 ms | 3408 KB | Output is correct |
22 | Correct | 28 ms | 3408 KB | Output is correct |
23 | Correct | 16 ms | 3408 KB | Output is correct |
24 | Correct | 43 ms | 3420 KB | Output is correct |
25 | Correct | 33 ms | 3420 KB | Output is correct |
26 | Correct | 50 ms | 3584 KB | Output is correct |
27 | Correct | 195 ms | 3408 KB | Output is correct |
28 | Correct | 210 ms | 3460 KB | Output is correct |
29 | Correct | 194 ms | 3524 KB | Output is correct |
30 | Correct | 195 ms | 3520 KB | Output is correct |
31 | Correct | 195 ms | 3408 KB | Output is correct |
32 | Correct | 206 ms | 3408 KB | Output is correct |
33 | Correct | 199 ms | 3408 KB | Output is correct |
34 | Correct | 202 ms | 3408 KB | Output is correct |
35 | Correct | 200 ms | 3408 KB | Output is correct |
36 | Correct | 208 ms | 3408 KB | Output is correct |
37 | Correct | 204 ms | 3400 KB | Output is correct |