# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
899056 |
2024-01-05T12:26:56 Z |
lovrot |
Tents (JOI18_tents) |
C++17 |
|
270 ms |
71880 KB |
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 3010;
const int MOD = 1e9 + 7;
inline int add(int a, int b) {
if(a + b < MOD) return a + b;
return a + b - MOD;
}
inline int mult(int a, int b) {
return (ll) a * b % MOD;
}
inline int pot(int a, int b) {
int ret = 1;
for(; b; b /= 2, a = mult(a, a))
if(b & 1) ret = mult(ret, a);
return ret;
}
inline int inv(int a) {
return pot(a, MOD - 2);
}
int w, h;
int C[N][N], DP[N][N];
int choose(int a, int b) {
if(a == b|| !b) return 1;
if(C[a][b] != -1) return C[a][b];
return C[a][b] = add(choose(a - 1, b), choose(a - 1, b - 1));
}
int dp(int n, int m) {
if(!n || !m) return 1;
if(DP[n][m] != -1) return DP[n][m];
int a = 0, b = 0, c = 0, d = 0;
a = dp(n - 1, m);
b = mult(mult(4, m), dp(n - 1, m - 1));
if(m > 1) c = mult(choose(m, 2), dp(n - 1, m - 2));
if(n > 1) d = mult(mult(m, n - 1), dp(n - 2, m - 1));
// printf("%d %d %d %d %d %d\n", n, m, a, b, c, d);
return DP[n][m] = add(a, add(b, add(c, d)));
}
int main() {
memset(C, -1, sizeof(C));
memset(DP, -1, sizeof(DP));
scanf("%d%d", &h, &w);
printf("%d\n", add(MOD - 1, dp(h, w)));
return 0;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
71260 KB |
Output is correct |
2 |
Correct |
8 ms |
71260 KB |
Output is correct |
3 |
Correct |
9 ms |
71260 KB |
Output is correct |
4 |
Correct |
9 ms |
71316 KB |
Output is correct |
5 |
Correct |
9 ms |
71512 KB |
Output is correct |
6 |
Correct |
9 ms |
71260 KB |
Output is correct |
7 |
Correct |
9 ms |
71260 KB |
Output is correct |
8 |
Correct |
9 ms |
71260 KB |
Output is correct |
9 |
Correct |
8 ms |
71260 KB |
Output is correct |
10 |
Correct |
10 ms |
71276 KB |
Output is correct |
11 |
Correct |
9 ms |
71256 KB |
Output is correct |
12 |
Correct |
11 ms |
71276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
71260 KB |
Output is correct |
2 |
Correct |
8 ms |
71260 KB |
Output is correct |
3 |
Correct |
9 ms |
71260 KB |
Output is correct |
4 |
Correct |
9 ms |
71316 KB |
Output is correct |
5 |
Correct |
9 ms |
71512 KB |
Output is correct |
6 |
Correct |
9 ms |
71260 KB |
Output is correct |
7 |
Correct |
9 ms |
71260 KB |
Output is correct |
8 |
Correct |
9 ms |
71260 KB |
Output is correct |
9 |
Correct |
8 ms |
71260 KB |
Output is correct |
10 |
Correct |
10 ms |
71276 KB |
Output is correct |
11 |
Correct |
9 ms |
71256 KB |
Output is correct |
12 |
Correct |
11 ms |
71276 KB |
Output is correct |
13 |
Correct |
9 ms |
71344 KB |
Output is correct |
14 |
Correct |
9 ms |
71516 KB |
Output is correct |
15 |
Correct |
185 ms |
71684 KB |
Output is correct |
16 |
Correct |
11 ms |
71260 KB |
Output is correct |
17 |
Correct |
27 ms |
71348 KB |
Output is correct |
18 |
Correct |
50 ms |
71260 KB |
Output is correct |
19 |
Correct |
206 ms |
71696 KB |
Output is correct |
20 |
Correct |
164 ms |
71512 KB |
Output is correct |
21 |
Correct |
96 ms |
71564 KB |
Output is correct |
22 |
Correct |
111 ms |
71512 KB |
Output is correct |
23 |
Correct |
74 ms |
71880 KB |
Output is correct |
24 |
Correct |
270 ms |
71760 KB |
Output is correct |
25 |
Correct |
199 ms |
71680 KB |
Output is correct |
26 |
Correct |
228 ms |
71512 KB |
Output is correct |
27 |
Correct |
264 ms |
71512 KB |
Output is correct |