# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1033965 |
2024-07-25T08:08:47 Z |
vjudge1 |
Tents (JOI18_tents) |
C++17 |
|
213 ms |
71300 KB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define pll pair<long long, long long>
#define se second
#define isz(a) (int)a.size()
using namespace std;
const long long inf = 1e18;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;
int n, m, divi;
int cc[maxn][maxn];
long long binpow(int x, int y){
long long ans = 1;
while (y){
if (y & 1) ans = ans * x % mod;
x = x * x % mod; y >>= 1;
}
return ans;
}
int dp(int i, int j){
if (i < 0 || j < 0) return 0;
if (cc[i][j] != -1) return cc[i][j];
int ans = 0;
ans += dp(i - 1, j); ans %= mod;
ans += dp(i - 1, j - 2) * j % mod * (j - 1) % mod * divi % mod; ans %= mod;
ans += dp(i - 2, j - 1) * j % mod * (i - 1) % mod; ans %= mod;
ans += dp(i - 1, j - 1) * j % mod * 4 % mod; ans %= mod;
// cout << ans << endl;
// cout << i << " " << j << " " << cc[i][j] << endl;
return cc[i][j] = ans;
}
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j) cc[i][j] = -1;
}
divi = binpow(2, mod - 2);
for (int i = 0; i <= n; ++i) cc[i][0] = 1;
for (int i = 0; i <= m; ++i) cc[0][i] = 1;
// cc[1][1] = 4;
cout << ((dp(n, m) - 1)%mod + mod)%mod << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
3 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
3 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
138 ms |
59752 KB |
Output is correct |
16 |
Correct |
3 ms |
6748 KB |
Output is correct |
17 |
Correct |
14 ms |
17080 KB |
Output is correct |
18 |
Correct |
52 ms |
17316 KB |
Output is correct |
19 |
Correct |
166 ms |
64096 KB |
Output is correct |
20 |
Correct |
127 ms |
52476 KB |
Output is correct |
21 |
Correct |
73 ms |
35676 KB |
Output is correct |
22 |
Correct |
114 ms |
38748 KB |
Output is correct |
23 |
Correct |
55 ms |
42584 KB |
Output is correct |
24 |
Correct |
202 ms |
71300 KB |
Output is correct |
25 |
Correct |
146 ms |
61532 KB |
Output is correct |
26 |
Correct |
168 ms |
66908 KB |
Output is correct |
27 |
Correct |
213 ms |
69416 KB |
Output is correct |