#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int mod = 1e9 + 7;
struct mint {
int v;
mint(long long x) {
if (x >= mod) x %= mod;
v = x;
}
mint() {v = 0;}
mint& operator+=(mint b) {
if ((v += b.v) >= mod) {
v -= mod;
}
return *this;
}
mint& operator-=(mint b) {
if ((v -= b.v) < 0) {
v += mod;
}
return *this;
}
mint& operator*=(mint b) {
v = 1ll * v * b.v % mod;
return *this;
}
mint power(mint a, int b) {
mint ans = 1;
while (b) {
if (b & 1) {
ans *= a;
}
a *= a, b >>= 1;
}
return ans;
}
mint& operator/=(mint b) {
v = 1ll * v * power(b, mod - 2).v % mod;
return *this;
}
friend mint operator+(mint a, mint b) {
return a += b;
}
friend mint operator-(mint a, mint b) {
return a -= b;
}
friend mint operator*(mint a, mint b) {
return a *= b;
}
friend mint operator/(mint a, mint b) {
return a /= b;
}
friend istream& operator>>(istream &is, mint a) {
return is >> a.v;
}
friend ostream& operator<<(ostream &os, mint a) {
return os << a.v;
}
};
const int N = 4005;
mint dp[N][N], fact[N], inv[N];
mint nCr(int n, int r) {
return fact[n] * inv[n - r] * inv[r];
}
mint nPr(int n, int r) {
return fact[n] * inv[n - r];
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
fact[0] = 1;
for (int i = 1; i < N; i++) {
fact[i] = fact[i - 1] * i;
}
inv[N - 1] = 1 / fact[N - 1];
for (int i = N - 2; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1);
}
int n, m;
cin >> n >> m;
int a[m]{};
for (int i = 0; i < 2 * n; i++) {
a[i % m]++;
}
dp[m][0] = 1;
for (int i = m - 1; i >= 0; i--) {
for (int j = 0; j <= 2 * n; j++) {
for (int k = 0; k <= min(j, a[i]); k++) {
dp[i][j] += dp[i + 1][a[i] - k + j - k] * nPr(a[i], k) * nCr(j, k);
}
}
}
cout << dp[0][0] * fact[n] * mint().power(2, n) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63064 KB |
Output is correct |
2 |
Correct |
8 ms |
63064 KB |
Output is correct |
3 |
Correct |
8 ms |
63068 KB |
Output is correct |
4 |
Correct |
8 ms |
63396 KB |
Output is correct |
5 |
Correct |
8 ms |
63068 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
8 ms |
63084 KB |
Output is correct |
8 |
Correct |
8 ms |
63068 KB |
Output is correct |
9 |
Correct |
8 ms |
63128 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63064 KB |
Output is correct |
2 |
Correct |
8 ms |
63064 KB |
Output is correct |
3 |
Correct |
8 ms |
63068 KB |
Output is correct |
4 |
Correct |
8 ms |
63396 KB |
Output is correct |
5 |
Correct |
8 ms |
63068 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
8 ms |
63084 KB |
Output is correct |
8 |
Correct |
8 ms |
63068 KB |
Output is correct |
9 |
Correct |
8 ms |
63128 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63096 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
8 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
63064 KB |
Output is correct |
15 |
Correct |
8 ms |
63064 KB |
Output is correct |
16 |
Correct |
8 ms |
63144 KB |
Output is correct |
17 |
Correct |
9 ms |
63608 KB |
Output is correct |
18 |
Correct |
8 ms |
63112 KB |
Output is correct |
19 |
Correct |
8 ms |
63192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63064 KB |
Output is correct |
2 |
Correct |
8 ms |
63064 KB |
Output is correct |
3 |
Correct |
8 ms |
63068 KB |
Output is correct |
4 |
Correct |
8 ms |
63396 KB |
Output is correct |
5 |
Correct |
8 ms |
63068 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
8 ms |
63084 KB |
Output is correct |
8 |
Correct |
8 ms |
63068 KB |
Output is correct |
9 |
Correct |
8 ms |
63128 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63096 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
8 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
63064 KB |
Output is correct |
15 |
Correct |
8 ms |
63064 KB |
Output is correct |
16 |
Correct |
8 ms |
63144 KB |
Output is correct |
17 |
Correct |
9 ms |
63608 KB |
Output is correct |
18 |
Correct |
8 ms |
63112 KB |
Output is correct |
19 |
Correct |
8 ms |
63192 KB |
Output is correct |
20 |
Correct |
9 ms |
63068 KB |
Output is correct |
21 |
Correct |
9 ms |
63064 KB |
Output is correct |
22 |
Correct |
11 ms |
63068 KB |
Output is correct |
23 |
Correct |
11 ms |
63068 KB |
Output is correct |
24 |
Correct |
12 ms |
63140 KB |
Output is correct |
25 |
Correct |
11 ms |
63264 KB |
Output is correct |
26 |
Correct |
10 ms |
63068 KB |
Output is correct |
27 |
Correct |
13 ms |
63068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63064 KB |
Output is correct |
2 |
Correct |
8 ms |
63064 KB |
Output is correct |
3 |
Correct |
8 ms |
63068 KB |
Output is correct |
4 |
Correct |
8 ms |
63396 KB |
Output is correct |
5 |
Correct |
8 ms |
63068 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
8 ms |
63084 KB |
Output is correct |
8 |
Correct |
8 ms |
63068 KB |
Output is correct |
9 |
Correct |
8 ms |
63128 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63096 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
8 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
63064 KB |
Output is correct |
15 |
Correct |
8 ms |
63064 KB |
Output is correct |
16 |
Correct |
8 ms |
63144 KB |
Output is correct |
17 |
Correct |
9 ms |
63608 KB |
Output is correct |
18 |
Correct |
8 ms |
63112 KB |
Output is correct |
19 |
Correct |
8 ms |
63192 KB |
Output is correct |
20 |
Correct |
9 ms |
63068 KB |
Output is correct |
21 |
Correct |
9 ms |
63064 KB |
Output is correct |
22 |
Correct |
11 ms |
63068 KB |
Output is correct |
23 |
Correct |
11 ms |
63068 KB |
Output is correct |
24 |
Correct |
12 ms |
63140 KB |
Output is correct |
25 |
Correct |
11 ms |
63264 KB |
Output is correct |
26 |
Correct |
10 ms |
63068 KB |
Output is correct |
27 |
Correct |
13 ms |
63068 KB |
Output is correct |
28 |
Correct |
20 ms |
63244 KB |
Output is correct |
29 |
Correct |
28 ms |
63068 KB |
Output is correct |
30 |
Correct |
28 ms |
63064 KB |
Output is correct |
31 |
Correct |
20 ms |
63068 KB |
Output is correct |
32 |
Correct |
29 ms |
63068 KB |
Output is correct |
33 |
Correct |
32 ms |
63068 KB |
Output is correct |
34 |
Correct |
49 ms |
63068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63064 KB |
Output is correct |
2 |
Correct |
8 ms |
63064 KB |
Output is correct |
3 |
Correct |
8 ms |
63068 KB |
Output is correct |
4 |
Correct |
8 ms |
63396 KB |
Output is correct |
5 |
Correct |
8 ms |
63068 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
8 ms |
63084 KB |
Output is correct |
8 |
Correct |
8 ms |
63068 KB |
Output is correct |
9 |
Correct |
8 ms |
63128 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63096 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
8 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
63064 KB |
Output is correct |
15 |
Correct |
8 ms |
63064 KB |
Output is correct |
16 |
Correct |
8 ms |
63144 KB |
Output is correct |
17 |
Correct |
9 ms |
63608 KB |
Output is correct |
18 |
Correct |
8 ms |
63112 KB |
Output is correct |
19 |
Correct |
8 ms |
63192 KB |
Output is correct |
20 |
Correct |
9 ms |
63068 KB |
Output is correct |
21 |
Correct |
9 ms |
63064 KB |
Output is correct |
22 |
Correct |
11 ms |
63068 KB |
Output is correct |
23 |
Correct |
11 ms |
63068 KB |
Output is correct |
24 |
Correct |
12 ms |
63140 KB |
Output is correct |
25 |
Correct |
11 ms |
63264 KB |
Output is correct |
26 |
Correct |
10 ms |
63068 KB |
Output is correct |
27 |
Correct |
13 ms |
63068 KB |
Output is correct |
28 |
Correct |
20 ms |
63244 KB |
Output is correct |
29 |
Correct |
28 ms |
63068 KB |
Output is correct |
30 |
Correct |
28 ms |
63064 KB |
Output is correct |
31 |
Correct |
20 ms |
63068 KB |
Output is correct |
32 |
Correct |
29 ms |
63068 KB |
Output is correct |
33 |
Correct |
32 ms |
63068 KB |
Output is correct |
34 |
Correct |
49 ms |
63068 KB |
Output is correct |
35 |
Correct |
89 ms |
63324 KB |
Output is correct |
36 |
Correct |
166 ms |
63248 KB |
Output is correct |
37 |
Correct |
83 ms |
63064 KB |
Output is correct |
38 |
Correct |
116 ms |
63244 KB |
Output is correct |
39 |
Correct |
130 ms |
63064 KB |
Output is correct |
40 |
Correct |
211 ms |
63248 KB |
Output is correct |