# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034136 |
2024-07-25T10:02:01 Z |
vjudge1 |
Tents (JOI18_tents) |
C++17 |
|
219 ms |
71240 KB |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define int long long
int dp[3003][3003];
int dv;
int bp(int a, int b){
if(b == 0) return 1;
if(b == 1) return a;
int k = bp(a, b/2);
k = (k * k) % mod;
if(b % 2 == 0) return k;
return (a * k) % mod;
}
int cal(int i, int j){
if(i < 0 || j < 0) return 0;
if(dp[i][j] != -1) return dp[i][j];
int ans = 0;
ans = (ans + cal(i - 1, j)) % mod;
ans = (ans + cal(i - 1, j - 2) * j % mod * (j - 1) % mod * dv % mod) % mod;
ans = (ans + cal(i - 2, j - 1) * j % mod * (i - 1) % mod) % mod;
ans = (ans + cal(i - 1, j - 1) * j % mod * 4 % mod) % mod;
return dp[i][j] = ans;
}
signed main(){
int n, m;
cin >> n >> m;
dv = bp(2, mod - 2);
for(int i = 0; i <= n; i++) for(int j = 0; j <= m; j++) dp[i][j] = -1;
for(int i = 0; i <= n; i++) dp[i][0] = 1;
for(int i = 0; i <= m; i++) dp[0][i] = 1;
cout << (cal(n, m) - 1 + mod)%mod;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
1884 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
1884 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
2136 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
9820 KB |
Output is correct |
15 |
Correct |
138 ms |
55448 KB |
Output is correct |
16 |
Correct |
3 ms |
4184 KB |
Output is correct |
17 |
Correct |
17 ms |
13052 KB |
Output is correct |
18 |
Correct |
42 ms |
17244 KB |
Output is correct |
19 |
Correct |
156 ms |
63324 KB |
Output is correct |
20 |
Correct |
127 ms |
51280 KB |
Output is correct |
21 |
Correct |
74 ms |
33884 KB |
Output is correct |
22 |
Correct |
84 ms |
35676 KB |
Output is correct |
23 |
Correct |
57 ms |
27224 KB |
Output is correct |
24 |
Correct |
219 ms |
71240 KB |
Output is correct |
25 |
Correct |
152 ms |
61556 KB |
Output is correct |
26 |
Correct |
177 ms |
66904 KB |
Output is correct |
27 |
Correct |
196 ms |
69460 KB |
Output is correct |