# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
355453 |
2021-01-22T13:49:19 Z |
kostia244 |
Tents (JOI18_tents) |
C++17 |
|
210 ms |
91884 KB |
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
const int maxn = 3030, mod = 1e9 + 7;
int n, m, f[maxn][maxn], g[maxn][maxn], h[maxn][maxn], C[maxn][maxn], fact[maxn];
int nck(int n, int k) {
if(k > n || k < 0) return 0;
return C[n][k];
}
int calc(int N, int X, int Y) {//N total, X paired, Y single
int ans = nck(N, X)*1ll*nck(N-X, Y)%mod;
ans = ans*1ll*f[X][0]%mod;
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
for(int i = 0; i < maxn; i++)
for(int j = 0; j <= i; j++)
if(!j) C[i][j] = 1;
else C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
fact[0] = 1;
for(int i = 1; i < maxn; i++) fact[i] = fact[i-1]*1ll*i%mod;
cin >> n >> m;
f[0][0] = 1;
for(int i = 0; i < max(m, n); i++) {
for(int j = 0; j <= i; j++) {
(f[i+1][j+1] += f[i][j])%=mod;
if(j) f[i+1][j-1] = (f[i+1][j-1] + f[i][j]*1ll*j)%mod;
}
}
for(int i = 0; i <= max(m, n); i++) {
for(int j = 0; j <= max(m, n); j++) {
if(min(i, j) == 0) h[i][j] = 1;
else {
h[i][j] = (h[i-1][j] + h[i-1][j-1]*4ll*j)%mod;
}
}
}
int ans = mod-1;
for(int a = 0; a <= max(n, m); a++)
for(int b = 0; b <= max(n, m); b++) if(n-2*a-b >= 0 && m-2*b-a >= 0) {
int res = calc(n, 2*a, b)*1ll*calc(m, 2*b, a)%mod;
res = res*1ll*fact[a]%mod;
res = res*1ll*fact[b]%mod;
res = res*1ll*h[n-2*a-b][m-2*b-a]%mod;
ans = (ans + res)%mod;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
28652 KB |
Output is correct |
2 |
Correct |
24 ms |
30188 KB |
Output is correct |
3 |
Correct |
26 ms |
28780 KB |
Output is correct |
4 |
Correct |
25 ms |
30316 KB |
Output is correct |
5 |
Correct |
25 ms |
30828 KB |
Output is correct |
6 |
Correct |
24 ms |
30572 KB |
Output is correct |
7 |
Correct |
24 ms |
30444 KB |
Output is correct |
8 |
Correct |
25 ms |
30956 KB |
Output is correct |
9 |
Correct |
23 ms |
29548 KB |
Output is correct |
10 |
Correct |
25 ms |
31212 KB |
Output is correct |
11 |
Correct |
25 ms |
31340 KB |
Output is correct |
12 |
Correct |
29 ms |
31340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
28652 KB |
Output is correct |
2 |
Correct |
24 ms |
30188 KB |
Output is correct |
3 |
Correct |
26 ms |
28780 KB |
Output is correct |
4 |
Correct |
25 ms |
30316 KB |
Output is correct |
5 |
Correct |
25 ms |
30828 KB |
Output is correct |
6 |
Correct |
24 ms |
30572 KB |
Output is correct |
7 |
Correct |
24 ms |
30444 KB |
Output is correct |
8 |
Correct |
25 ms |
30956 KB |
Output is correct |
9 |
Correct |
23 ms |
29548 KB |
Output is correct |
10 |
Correct |
25 ms |
31212 KB |
Output is correct |
11 |
Correct |
25 ms |
31340 KB |
Output is correct |
12 |
Correct |
29 ms |
31340 KB |
Output is correct |
13 |
Correct |
61 ms |
63084 KB |
Output is correct |
14 |
Correct |
79 ms |
75244 KB |
Output is correct |
15 |
Correct |
171 ms |
86148 KB |
Output is correct |
16 |
Correct |
51 ms |
55168 KB |
Output is correct |
17 |
Correct |
66 ms |
62060 KB |
Output is correct |
18 |
Correct |
61 ms |
49772 KB |
Output is correct |
19 |
Correct |
175 ms |
89708 KB |
Output is correct |
20 |
Correct |
151 ms |
78836 KB |
Output is correct |
21 |
Correct |
106 ms |
69868 KB |
Output is correct |
22 |
Correct |
107 ms |
71788 KB |
Output is correct |
23 |
Correct |
114 ms |
91756 KB |
Output is correct |
24 |
Correct |
210 ms |
91884 KB |
Output is correct |
25 |
Correct |
166 ms |
82028 KB |
Output is correct |
26 |
Correct |
187 ms |
87404 KB |
Output is correct |
27 |
Correct |
204 ms |
90988 KB |
Output is correct |