#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2020
#define MAXS 22
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
ll fact[MAX * 2];
int A[MAX];
ll dp[MAX][MAX * 2];
ll C[MAX * 2][MAX * 2];
ll P[MAX * 2][MAX * 2];
void add(ll& a, ll b) { a = (a + b) % MOD; }
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
int i, j, k;
fact[0] = 1;
for (i = 1; i <= N * 2; i++) fact[i] = (fact[i - 1] * i) % MOD;
C[0][0] = 1;
for (i = 1; i <= N * 2; i++) {
C[i][0] = C[i][i] = 1;
for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
}
for (i = 0; i <= N * 2; i++) for (j = 0; j <= i; j++) P[i][j] = (C[i][j] * fact[j]) % MOD;
for (i = 1; i <= N * 2; i++) A[i % M]++;
dp[0][A[0]] = 1;
int sum = A[0];
for (i = 1; i < M; i++) {
for (j = 0; j <= sum; j++) for (k = 0; k <= min(j, A[i]); k++) dp[i][j + A[i] - k * 2] = (dp[i][j + A[i] - k * 2] + dp[i - 1][j] * ((P[A[i]][k] * C[j][k]) % MOD)) % MOD;
sum += A[i];
}
ll ans = (dp[M - 1][0] * fact[N]) % MOD;
for (i = 1; i <= N; i++) {
ans <<= 1;
ans %= MOD;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
3924 KB |
Output is correct |
21 |
Correct |
3 ms |
3924 KB |
Output is correct |
22 |
Correct |
7 ms |
8404 KB |
Output is correct |
23 |
Correct |
4 ms |
6100 KB |
Output is correct |
24 |
Correct |
7 ms |
8748 KB |
Output is correct |
25 |
Correct |
4 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
6612 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
3924 KB |
Output is correct |
21 |
Correct |
3 ms |
3924 KB |
Output is correct |
22 |
Correct |
7 ms |
8404 KB |
Output is correct |
23 |
Correct |
4 ms |
6100 KB |
Output is correct |
24 |
Correct |
7 ms |
8748 KB |
Output is correct |
25 |
Correct |
4 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
6612 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
28 |
Correct |
13 ms |
22740 KB |
Output is correct |
29 |
Correct |
19 ms |
27412 KB |
Output is correct |
30 |
Correct |
19 ms |
29228 KB |
Output is correct |
31 |
Correct |
13 ms |
23380 KB |
Output is correct |
32 |
Correct |
22 ms |
29200 KB |
Output is correct |
33 |
Correct |
26 ms |
34220 KB |
Output is correct |
34 |
Correct |
33 ms |
50132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
1 ms |
1748 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
1620 KB |
Output is correct |
18 |
Correct |
1 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
3924 KB |
Output is correct |
21 |
Correct |
3 ms |
3924 KB |
Output is correct |
22 |
Correct |
7 ms |
8404 KB |
Output is correct |
23 |
Correct |
4 ms |
6100 KB |
Output is correct |
24 |
Correct |
7 ms |
8748 KB |
Output is correct |
25 |
Correct |
4 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
6612 KB |
Output is correct |
27 |
Correct |
5 ms |
9812 KB |
Output is correct |
28 |
Correct |
13 ms |
22740 KB |
Output is correct |
29 |
Correct |
19 ms |
27412 KB |
Output is correct |
30 |
Correct |
19 ms |
29228 KB |
Output is correct |
31 |
Correct |
13 ms |
23380 KB |
Output is correct |
32 |
Correct |
22 ms |
29200 KB |
Output is correct |
33 |
Correct |
26 ms |
34220 KB |
Output is correct |
34 |
Correct |
33 ms |
50132 KB |
Output is correct |
35 |
Correct |
66 ms |
109308 KB |
Output is correct |
36 |
Correct |
163 ms |
159304 KB |
Output is correct |
37 |
Correct |
62 ms |
106820 KB |
Output is correct |
38 |
Correct |
107 ms |
126072 KB |
Output is correct |
39 |
Correct |
129 ms |
129124 KB |
Output is correct |
40 |
Correct |
199 ms |
194792 KB |
Output is correct |