#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[2001][2001];
int a[2001], s[2001];
int c[2001][2001];
const int MOD = 1e9 + 7;
void chadd(int& x, int y) { x += y; x %= MOD; }
int C(int n, int r){
if(r < 0 || r > n) return 0;
return c[n][r];
}
int32_t main(){
int N, M; cin >> N >> M;
for(int i = 0; i < M; i++) a[i] = (N * 2 + i) / M;
for(int i = 0; i < M; i++) s[i + 1] = s[i] + a[i];
dp[0][0] = 1;
for(int i = 0; i <= 2000; i++){
c[i][0] = c[i][i] = 1;
for(int j = 1; j < i; j++){
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
}
}
for(int i = 0; i < M; i++){
for(int j = 0; j <= N; j++){
for(int k = 0; k <= a[i]; k++){
int j2 = j + (a[i] - k) - k; if(j2 < 0 || j2 > N) continue;
chadd(dp[i + 1][j2], dp[i][j] * C(j, k) % MOD * C(N - (s[i] + j) / 2, a[i] - k) % MOD);
}
}
}
int ans = dp[M][0];
for(int i = 0; i < N; i++){
ans = ans * 2 % MOD;
}
for(int i = 0; i < M; i++){
for(int j = 1; j <= a[i]; j++){
ans = ans * j % MOD;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22996 KB |
Output is correct |
2 |
Correct |
13 ms |
22956 KB |
Output is correct |
3 |
Correct |
13 ms |
22992 KB |
Output is correct |
4 |
Correct |
12 ms |
22972 KB |
Output is correct |
5 |
Correct |
14 ms |
22992 KB |
Output is correct |
6 |
Correct |
12 ms |
23000 KB |
Output is correct |
7 |
Correct |
12 ms |
22996 KB |
Output is correct |
8 |
Correct |
13 ms |
22968 KB |
Output is correct |
9 |
Correct |
15 ms |
22968 KB |
Output is correct |
10 |
Correct |
12 ms |
22996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22996 KB |
Output is correct |
2 |
Correct |
13 ms |
22956 KB |
Output is correct |
3 |
Correct |
13 ms |
22992 KB |
Output is correct |
4 |
Correct |
12 ms |
22972 KB |
Output is correct |
5 |
Correct |
14 ms |
22992 KB |
Output is correct |
6 |
Correct |
12 ms |
23000 KB |
Output is correct |
7 |
Correct |
12 ms |
22996 KB |
Output is correct |
8 |
Correct |
13 ms |
22968 KB |
Output is correct |
9 |
Correct |
15 ms |
22968 KB |
Output is correct |
10 |
Correct |
12 ms |
22996 KB |
Output is correct |
11 |
Correct |
13 ms |
23260 KB |
Output is correct |
12 |
Correct |
13 ms |
23124 KB |
Output is correct |
13 |
Correct |
12 ms |
22956 KB |
Output is correct |
14 |
Correct |
12 ms |
23124 KB |
Output is correct |
15 |
Correct |
12 ms |
23216 KB |
Output is correct |
16 |
Correct |
12 ms |
23036 KB |
Output is correct |
17 |
Correct |
12 ms |
23124 KB |
Output is correct |
18 |
Correct |
14 ms |
23220 KB |
Output is correct |
19 |
Correct |
13 ms |
22996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22996 KB |
Output is correct |
2 |
Correct |
13 ms |
22956 KB |
Output is correct |
3 |
Correct |
13 ms |
22992 KB |
Output is correct |
4 |
Correct |
12 ms |
22972 KB |
Output is correct |
5 |
Correct |
14 ms |
22992 KB |
Output is correct |
6 |
Correct |
12 ms |
23000 KB |
Output is correct |
7 |
Correct |
12 ms |
22996 KB |
Output is correct |
8 |
Correct |
13 ms |
22968 KB |
Output is correct |
9 |
Correct |
15 ms |
22968 KB |
Output is correct |
10 |
Correct |
12 ms |
22996 KB |
Output is correct |
11 |
Correct |
13 ms |
23260 KB |
Output is correct |
12 |
Correct |
13 ms |
23124 KB |
Output is correct |
13 |
Correct |
12 ms |
22956 KB |
Output is correct |
14 |
Correct |
12 ms |
23124 KB |
Output is correct |
15 |
Correct |
12 ms |
23216 KB |
Output is correct |
16 |
Correct |
12 ms |
23036 KB |
Output is correct |
17 |
Correct |
12 ms |
23124 KB |
Output is correct |
18 |
Correct |
14 ms |
23220 KB |
Output is correct |
19 |
Correct |
13 ms |
22996 KB |
Output is correct |
20 |
Correct |
12 ms |
23032 KB |
Output is correct |
21 |
Correct |
13 ms |
23348 KB |
Output is correct |
22 |
Correct |
14 ms |
24532 KB |
Output is correct |
23 |
Correct |
15 ms |
23036 KB |
Output is correct |
24 |
Correct |
14 ms |
23892 KB |
Output is correct |
25 |
Correct |
14 ms |
24404 KB |
Output is correct |
26 |
Correct |
13 ms |
23088 KB |
Output is correct |
27 |
Correct |
15 ms |
24860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22996 KB |
Output is correct |
2 |
Correct |
13 ms |
22956 KB |
Output is correct |
3 |
Correct |
13 ms |
22992 KB |
Output is correct |
4 |
Correct |
12 ms |
22972 KB |
Output is correct |
5 |
Correct |
14 ms |
22992 KB |
Output is correct |
6 |
Correct |
12 ms |
23000 KB |
Output is correct |
7 |
Correct |
12 ms |
22996 KB |
Output is correct |
8 |
Correct |
13 ms |
22968 KB |
Output is correct |
9 |
Correct |
15 ms |
22968 KB |
Output is correct |
10 |
Correct |
12 ms |
22996 KB |
Output is correct |
11 |
Correct |
13 ms |
23260 KB |
Output is correct |
12 |
Correct |
13 ms |
23124 KB |
Output is correct |
13 |
Correct |
12 ms |
22956 KB |
Output is correct |
14 |
Correct |
12 ms |
23124 KB |
Output is correct |
15 |
Correct |
12 ms |
23216 KB |
Output is correct |
16 |
Correct |
12 ms |
23036 KB |
Output is correct |
17 |
Correct |
12 ms |
23124 KB |
Output is correct |
18 |
Correct |
14 ms |
23220 KB |
Output is correct |
19 |
Correct |
13 ms |
22996 KB |
Output is correct |
20 |
Correct |
12 ms |
23032 KB |
Output is correct |
21 |
Correct |
13 ms |
23348 KB |
Output is correct |
22 |
Correct |
14 ms |
24532 KB |
Output is correct |
23 |
Correct |
15 ms |
23036 KB |
Output is correct |
24 |
Correct |
14 ms |
23892 KB |
Output is correct |
25 |
Correct |
14 ms |
24404 KB |
Output is correct |
26 |
Correct |
13 ms |
23088 KB |
Output is correct |
27 |
Correct |
15 ms |
24860 KB |
Output is correct |
28 |
Correct |
17 ms |
23124 KB |
Output is correct |
29 |
Correct |
22 ms |
25964 KB |
Output is correct |
30 |
Correct |
28 ms |
28212 KB |
Output is correct |
31 |
Correct |
17 ms |
23028 KB |
Output is correct |
32 |
Correct |
21 ms |
26160 KB |
Output is correct |
33 |
Correct |
26 ms |
29096 KB |
Output is correct |
34 |
Correct |
35 ms |
32844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22996 KB |
Output is correct |
2 |
Correct |
13 ms |
22956 KB |
Output is correct |
3 |
Correct |
13 ms |
22992 KB |
Output is correct |
4 |
Correct |
12 ms |
22972 KB |
Output is correct |
5 |
Correct |
14 ms |
22992 KB |
Output is correct |
6 |
Correct |
12 ms |
23000 KB |
Output is correct |
7 |
Correct |
12 ms |
22996 KB |
Output is correct |
8 |
Correct |
13 ms |
22968 KB |
Output is correct |
9 |
Correct |
15 ms |
22968 KB |
Output is correct |
10 |
Correct |
12 ms |
22996 KB |
Output is correct |
11 |
Correct |
13 ms |
23260 KB |
Output is correct |
12 |
Correct |
13 ms |
23124 KB |
Output is correct |
13 |
Correct |
12 ms |
22956 KB |
Output is correct |
14 |
Correct |
12 ms |
23124 KB |
Output is correct |
15 |
Correct |
12 ms |
23216 KB |
Output is correct |
16 |
Correct |
12 ms |
23036 KB |
Output is correct |
17 |
Correct |
12 ms |
23124 KB |
Output is correct |
18 |
Correct |
14 ms |
23220 KB |
Output is correct |
19 |
Correct |
13 ms |
22996 KB |
Output is correct |
20 |
Correct |
12 ms |
23032 KB |
Output is correct |
21 |
Correct |
13 ms |
23348 KB |
Output is correct |
22 |
Correct |
14 ms |
24532 KB |
Output is correct |
23 |
Correct |
15 ms |
23036 KB |
Output is correct |
24 |
Correct |
14 ms |
23892 KB |
Output is correct |
25 |
Correct |
14 ms |
24404 KB |
Output is correct |
26 |
Correct |
13 ms |
23088 KB |
Output is correct |
27 |
Correct |
15 ms |
24860 KB |
Output is correct |
28 |
Correct |
17 ms |
23124 KB |
Output is correct |
29 |
Correct |
22 ms |
25964 KB |
Output is correct |
30 |
Correct |
28 ms |
28212 KB |
Output is correct |
31 |
Correct |
17 ms |
23028 KB |
Output is correct |
32 |
Correct |
21 ms |
26160 KB |
Output is correct |
33 |
Correct |
26 ms |
29096 KB |
Output is correct |
34 |
Correct |
35 ms |
32844 KB |
Output is correct |
35 |
Correct |
44 ms |
23192 KB |
Output is correct |
36 |
Correct |
166 ms |
49516 KB |
Output is correct |
37 |
Correct |
42 ms |
23252 KB |
Output is correct |
38 |
Correct |
81 ms |
35764 KB |
Output is correct |
39 |
Correct |
98 ms |
46420 KB |
Output is correct |
40 |
Correct |
167 ms |
54264 KB |
Output is correct |