# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
503707 |
2022-01-08T16:04:44 Z |
Stickfish |
NoM (RMI21_nom) |
C++17 |
|
500 ms |
5716 KB |
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll MAXN = 2077;
ll pw(ll a, ll m) {
if (!m)
return 1;
a %= MOD;
if (m % 2)
return a * pw(a, m - 1) % MOD;
return pw(a * a, m / 2);
}
ll fact[MAXN * 2];
ll rfact[MAXN * 2];
ll choose(ll n, ll k) {
if (n < 0 || k < 0 || k > n)
return 0;
return (fact[n] * rfact[k] % MOD) * rfact[n - k] % MOD;
}
ll dp[MAXN][MAXN];
signed main() {
fact[0] = rfact[0] = 1;
for (int i = 1; i < MAXN * 2; ++i) {
fact[i] = (fact[i - 1] * i) % MOD;
rfact[i] = pw(fact[i], MOD - 2);
}
int n, m;
cin >> n >> m;
//if (m == 1) {
//cout << 0 << endl;
//return 0;
//}
int sz = 2 * n / m;
int szinc = 2 * n % m;
int smsz = sz + int(0 < szinc);
dp[0][0] = (choose(n, smsz) * fact[smsz]) % MOD;
//cout << dp[0][0] << endl;
for (int i = 1; i < m; ++i) {
int szi = sz + int(i < szinc);
for (int c = 0; c <= n; ++c) {
for (int cp = 0; cp <= c; ++cp) {
ll cnt1 = smsz - cp * 2;
ll cnt0 = n - cp - cnt1;
//if (cnt1 < 0 || cnt0 < 0)
//continue;
dp[i][c] += (dp[i - 1][cp] * choose(cnt1, c - cp) % MOD) * choose(cnt0, szi - (c - cp));
dp[i][c] %= MOD;
}
dp[i][c] *= fact[szi];
dp[i][c] %= MOD;
//cout << dp[i][c] << ' ';
}
smsz += szi;
//cout << endl;
}
cout << dp[m - 1][n] * pw(2, n) % MOD << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
7 ms |
716 KB |
Output is correct |
22 |
Correct |
57 ms |
1856 KB |
Output is correct |
23 |
Correct |
5 ms |
460 KB |
Output is correct |
24 |
Correct |
38 ms |
1184 KB |
Output is correct |
25 |
Correct |
50 ms |
1820 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
76 ms |
2240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
7 ms |
716 KB |
Output is correct |
22 |
Correct |
57 ms |
1856 KB |
Output is correct |
23 |
Correct |
5 ms |
460 KB |
Output is correct |
24 |
Correct |
38 ms |
1184 KB |
Output is correct |
25 |
Correct |
50 ms |
1820 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
76 ms |
2240 KB |
Output is correct |
28 |
Correct |
27 ms |
560 KB |
Output is correct |
29 |
Correct |
423 ms |
3288 KB |
Output is correct |
30 |
Execution timed out |
726 ms |
5716 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
7 ms |
716 KB |
Output is correct |
22 |
Correct |
57 ms |
1856 KB |
Output is correct |
23 |
Correct |
5 ms |
460 KB |
Output is correct |
24 |
Correct |
38 ms |
1184 KB |
Output is correct |
25 |
Correct |
50 ms |
1820 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
76 ms |
2240 KB |
Output is correct |
28 |
Correct |
27 ms |
560 KB |
Output is correct |
29 |
Correct |
423 ms |
3288 KB |
Output is correct |
30 |
Execution timed out |
726 ms |
5716 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |