#include <iostream>
#define MOD 1000000007
#define MAXN 10000
using namespace std;
long long dp[MAXN + 1][2];
int val[MAXN];
long long fact[MAXN + 1];
long long invFact[MAXN + 1];
int m, n;
long long makeInv(long long x) {
int pow;
long long ans;
ans = 1;
pow = MOD - 2;
while ( pow ) {
if ( pow % 2 ) {
ans = (ans * x) % MOD;
}
pow /= 2;
x = (x * x) % MOD;
}
return ans;
}
void makeFact() {
long long ans;
int i;
ans = 1;
fact[0] = invFact[0] = 1;
for ( i = 1; i <= MAXN; i++ ) {
ans = (ans * i) % MOD;
fact[i] = ans;
invFact[i] = makeInv(ans);
}
}
long long makeCombi(int n, int choose) {
if ( n >= choose && choose >= 0 ) {
return (((fact[n] * invFact[choose]) % MOD) * invFact[n - choose]) % MOD;
}
return 0;
}
long long makeChoose(int n, int choose) {
if ( n >= choose && choose >= 0 ) {
return (fact[n] * invFact[n - choose]) % MOD;
}
return 0;
}
long long calcAns(int a, int b, int x) { ///from a to b(x from b have pair); we choose from a increasing, other does not matter
if ( a >= x && x >= 0 && b >= x ) {
return (makeCombi(a, x) * makeChoose(b, x)) % MOD;
}
return 0;
}
void smh() {
int currNr, i, pos, i2, i3;
//makeFact();
//scanf("%d%d", &n, &m);
n *= 2;
for ( i = 0; i < n; i++ ) {
val[i % m]++;
}
pos = 0;
dp[0][0] = 1;
currNr = 0;
for ( i = 0; i < m; i++ ) {
pos ^= 1;
for ( i2 = 0; i2 <= MAXN; i2++ ) {
dp[i2][pos] = 0;
}
for ( i2 = 0; i2 <= val[i]; i2++ ) { //how many we pair
for ( i3 = 0; i3 <= currNr; i3++ ) { //how many are used
dp[i3 + 2 * i2][pos] = (dp[i3 + 2 * i2][pos] + (dp[i3][pos ^ 1] * calcAns(currNr - i3, val[i], i2)) % MOD) % MOD;
}
}
currNr += val[i];
}
long long pow;
pow = 1;
for ( i = 1; i <= n / 2; i++ ) {
pow = ((long long) pow * 2) % MOD;
}
printf("%lld\n", (((dp[n][pos] * fact[n / 2]) % MOD) * pow) % MOD);
}
int main() {
makeFact();
scanf("%d%d", &n, &m);
smh();
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
600 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
600 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
9 ms |
604 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
20 ms |
756 KB |
Output is correct |
31 |
Correct |
9 ms |
600 KB |
Output is correct |
32 |
Correct |
15 ms |
604 KB |
Output is correct |
33 |
Correct |
19 ms |
604 KB |
Output is correct |
34 |
Correct |
30 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
600 KB |
Output is correct |
27 |
Correct |
6 ms |
604 KB |
Output is correct |
28 |
Correct |
9 ms |
604 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
20 ms |
756 KB |
Output is correct |
31 |
Correct |
9 ms |
600 KB |
Output is correct |
32 |
Correct |
15 ms |
604 KB |
Output is correct |
33 |
Correct |
19 ms |
604 KB |
Output is correct |
34 |
Correct |
30 ms |
592 KB |
Output is correct |
35 |
Correct |
54 ms |
604 KB |
Output is correct |
36 |
Correct |
112 ms |
736 KB |
Output is correct |
37 |
Correct |
49 ms |
604 KB |
Output is correct |
38 |
Correct |
73 ms |
604 KB |
Output is correct |
39 |
Correct |
81 ms |
604 KB |
Output is correct |
40 |
Correct |
130 ms |
744 KB |
Output is correct |