// nom_100_mihai.cpp
#include <bits/stdc++.h>
using namespace std;
const int DIM = 2000;
const int mod = 1e9 + 7;
int comb[2 * DIM + 1][2 * DIM + 1];
int fact[2 * DIM + 1];
int cnt[DIM + 1];
int dp[DIM + 1][DIM + 1];
int pre[DIM + 1];
inline void add(int& x, int y) {
x += y;
if (x >= mod)
x -= mod;
}
void precalc(int n, int m)
{
fact[0] = 1;
for(int i = 0; i <= 2 * n; ++i)
{
comb[i][0] = 1;
if(i >= 1)
fact[i] = (fact[i - 1] * 1LL * i) % mod;
for(int j = 1; j <= i; ++j)
{
add(comb[i][j], comb[i - 1][j]);
add(comb[i][j], comb[i - 1][j - 1]);
}
}
for(int i = 0; i < 2 * n; ++i)
++cnt[i % m];
pre[0] = cnt[0];
for(int i = 1; i < m; ++i)
pre[i] = pre[i - 1] + cnt[i];
}
main()
{
int n, m;
cin >> n >> m;
precalc(n, m);
dp[0][0] = (comb[n][cnt[0]] * 1LL * fact[cnt[0]]) % mod;
for(int rest = 0; rest < m - 1; ++rest)
for(int dubluri = 0; dubluri <= n; ++dubluri)
if(dp[rest][dubluri])
{
for(int extra = 0; extra <= cnt[rest + 1] && extra + dubluri <= n; ++extra)
{
int a = dp[rest][dubluri];
int b = comb[pre[rest] - 2 * dubluri][extra];
int c = comb[n - pre[rest] + dubluri][cnt[rest + 1] - extra];
int d = fact[cnt[rest + 1]];
a = (a * 1LL * b) % mod;
a = (a * 1LL * c) % mod;
a = (a * 1LL * d) % mod;
add(dp[rest + 1][dubluri + extra], a);
}
}
int ans = dp[m - 1][n];
for(int i = 1; i <= n; ++i)
ans = (ans * 2) % mod;
cout << ans << '\n';
}
Compilation message
Main.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1996 KB |
Output is correct |
22 |
Correct |
3 ms |
4044 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
3916 KB |
Output is correct |
25 |
Correct |
5 ms |
3884 KB |
Output is correct |
26 |
Correct |
4 ms |
2892 KB |
Output is correct |
27 |
Correct |
3 ms |
4684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1996 KB |
Output is correct |
22 |
Correct |
3 ms |
4044 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
3916 KB |
Output is correct |
25 |
Correct |
5 ms |
3884 KB |
Output is correct |
26 |
Correct |
4 ms |
2892 KB |
Output is correct |
27 |
Correct |
3 ms |
4684 KB |
Output is correct |
28 |
Correct |
7 ms |
8524 KB |
Output is correct |
29 |
Correct |
9 ms |
10444 KB |
Output is correct |
30 |
Correct |
14 ms |
11472 KB |
Output is correct |
31 |
Correct |
8 ms |
8652 KB |
Output is correct |
32 |
Correct |
11 ms |
11084 KB |
Output is correct |
33 |
Correct |
26 ms |
13088 KB |
Output is correct |
34 |
Correct |
25 ms |
18292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
1356 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1996 KB |
Output is correct |
22 |
Correct |
3 ms |
4044 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
3916 KB |
Output is correct |
25 |
Correct |
5 ms |
3884 KB |
Output is correct |
26 |
Correct |
4 ms |
2892 KB |
Output is correct |
27 |
Correct |
3 ms |
4684 KB |
Output is correct |
28 |
Correct |
7 ms |
8524 KB |
Output is correct |
29 |
Correct |
9 ms |
10444 KB |
Output is correct |
30 |
Correct |
14 ms |
11472 KB |
Output is correct |
31 |
Correct |
8 ms |
8652 KB |
Output is correct |
32 |
Correct |
11 ms |
11084 KB |
Output is correct |
33 |
Correct |
26 ms |
13088 KB |
Output is correct |
34 |
Correct |
25 ms |
18292 KB |
Output is correct |
35 |
Correct |
37 ms |
33952 KB |
Output is correct |
36 |
Correct |
66 ms |
48472 KB |
Output is correct |
37 |
Correct |
50 ms |
33228 KB |
Output is correct |
38 |
Correct |
53 ms |
39264 KB |
Output is correct |
39 |
Correct |
75 ms |
40892 KB |
Output is correct |
40 |
Correct |
143 ms |
57560 KB |
Output is correct |