#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll mpow(ll x, ll y){
if(!y) return 1;
if(y&1) return mpow(x, y-1) * x % MOD;
ll tmp = mpow(x, y/2);
return tmp*tmp%MOD;
}
int n, m;
ll fact[10002];
ll factInv[10002];
ll arr[10002];
ll DP[3002][3002];
ll ans;
ll comb(ll x, ll y){
if(x<y) return 0;
return fact[x] * factInv[y] % MOD * factInv[x-y] % MOD;
}
int main(){
scanf("%d %d", &n, &m);
fact[0] = 1;
for(int i=1; i<=10000; i++) fact[i] = fact[i-1] * i % MOD;
factInv[10000] = mpow(fact[10000], MOD-2);
for(int i=9999; i>=0; i--) factInv[i] = factInv[i+1] * (i+1) % MOD;
for(int i=0; i<=3000; i++){
arr[i] = 1;
for(int j=0; j<i; j++){
arr[i] = arr[i] * comb(2*(i-j), 2) % MOD;
}
}
for(int i=0; i<=n; i++){
for(int j=0; j<=m; j++){
if(i==0 || j==0){
DP[i][j] = 1;
continue;
}
DP[i][j] = DP[i-1][j];
DP[i][j] += DP[i-1][j-1] * j * 4;
DP[i][j] %= MOD;
}
}
for(int i=0; i<=n; i++){
for(int j=0; j<=m; j++){
if(i+2*j > n || j+2*i > m) continue;
ll c1 = comb(n, i) * comb(m, j) % MOD;
ll c2 = comb(n-i, j+j) * comb(m-j, i+i) % MOD;
ll c3 = arr[i] * arr[j] % MOD;
ll c4 = DP[n-i-j-j][m-j-i-i];
ans += c1 * c2 % MOD * c3 % MOD * c4 % MOD;
ans %= MOD;
}
}
printf("%lld", ans-1);
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
28 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
492 KB |
Output is correct |
2 |
Correct |
39 ms |
492 KB |
Output is correct |
3 |
Correct |
39 ms |
748 KB |
Output is correct |
4 |
Correct |
40 ms |
1388 KB |
Output is correct |
5 |
Correct |
39 ms |
876 KB |
Output is correct |
6 |
Correct |
39 ms |
1644 KB |
Output is correct |
7 |
Correct |
40 ms |
1260 KB |
Output is correct |
8 |
Correct |
39 ms |
1644 KB |
Output is correct |
9 |
Correct |
39 ms |
1132 KB |
Output is correct |
10 |
Correct |
40 ms |
2028 KB |
Output is correct |
11 |
Correct |
39 ms |
620 KB |
Output is correct |
12 |
Correct |
41 ms |
2412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
492 KB |
Output is correct |
2 |
Correct |
39 ms |
492 KB |
Output is correct |
3 |
Correct |
39 ms |
748 KB |
Output is correct |
4 |
Correct |
40 ms |
1388 KB |
Output is correct |
5 |
Correct |
39 ms |
876 KB |
Output is correct |
6 |
Correct |
39 ms |
1644 KB |
Output is correct |
7 |
Correct |
40 ms |
1260 KB |
Output is correct |
8 |
Correct |
39 ms |
1644 KB |
Output is correct |
9 |
Correct |
39 ms |
1132 KB |
Output is correct |
10 |
Correct |
40 ms |
2028 KB |
Output is correct |
11 |
Correct |
39 ms |
620 KB |
Output is correct |
12 |
Correct |
41 ms |
2412 KB |
Output is correct |
13 |
Correct |
39 ms |
620 KB |
Output is correct |
14 |
Correct |
43 ms |
9836 KB |
Output is correct |
15 |
Correct |
165 ms |
55532 KB |
Output is correct |
16 |
Correct |
43 ms |
4204 KB |
Output is correct |
17 |
Correct |
56 ms |
13036 KB |
Output is correct |
18 |
Correct |
78 ms |
17260 KB |
Output is correct |
19 |
Correct |
188 ms |
63212 KB |
Output is correct |
20 |
Correct |
168 ms |
51180 KB |
Output is correct |
21 |
Correct |
101 ms |
34156 KB |
Output is correct |
22 |
Correct |
113 ms |
35820 KB |
Output is correct |
23 |
Correct |
64 ms |
27244 KB |
Output is correct |
24 |
Correct |
247 ms |
71020 KB |
Output is correct |
25 |
Correct |
191 ms |
61548 KB |
Output is correct |
26 |
Correct |
218 ms |
66780 KB |
Output is correct |
27 |
Correct |
233 ms |
69100 KB |
Output is correct |