# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
716691 |
2023-03-30T19:38:12 Z |
Sohsoh84 |
Tents (JOI18_tents) |
C++17 |
|
288 ms |
71380 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 3e3 + 10;
const ll MOD = 1e9 + 7;
const ll INV2 = (MOD + 1) / 2;
inline ll poww(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return ans;
}
ll fact[MAXN], inv[MAXN], n, m, dp[MAXN][MAXN];;
inline ll C(ll k, ll n) {
if (k < 0 || k > n) return 0;
return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}
inline ll calc(ll n, ll m, ll k) {
return C(k, n) * C(2 * k, m) % MOD * fact[2 * k] % MOD * poww(INV2, k) % MOD;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll ans = 0;
fact[0] = inv[0] = 1;
for (int i = 1; i < MAXN; i++) {
fact[i] = fact[i - 1] * i % MOD;
inv[i] = poww(fact[i], MOD - 2);
}
for (int i = 0; i < MAXN; i++) {
for (int j = 0; j < MAXN; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 1;
continue;
}
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] * j * 4) % MOD;
}
}
cin >> n >> m;
for (int i = 0; i <= n; i++) {
for (int j = 0; 2 * i + j <= m && i + 2 * j <= n; j++) {
ll tans = calc(n, m, i) * calc(m - 2 * i, n - i, j) % MOD * dp[n - i - 2 * j][m - 2 * i - j] % MOD;
ans = (ans + tans) % MOD;
}
}
cout << (ans + MOD - 1) % MOD << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
71244 KB |
Output is correct |
2 |
Correct |
58 ms |
71256 KB |
Output is correct |
3 |
Correct |
44 ms |
71296 KB |
Output is correct |
4 |
Correct |
43 ms |
71264 KB |
Output is correct |
5 |
Correct |
42 ms |
71200 KB |
Output is correct |
6 |
Correct |
51 ms |
71204 KB |
Output is correct |
7 |
Correct |
46 ms |
71200 KB |
Output is correct |
8 |
Correct |
46 ms |
71268 KB |
Output is correct |
9 |
Correct |
43 ms |
71168 KB |
Output is correct |
10 |
Correct |
44 ms |
71224 KB |
Output is correct |
11 |
Correct |
46 ms |
71244 KB |
Output is correct |
12 |
Correct |
51 ms |
71140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
71244 KB |
Output is correct |
2 |
Correct |
58 ms |
71256 KB |
Output is correct |
3 |
Correct |
44 ms |
71296 KB |
Output is correct |
4 |
Correct |
43 ms |
71264 KB |
Output is correct |
5 |
Correct |
42 ms |
71200 KB |
Output is correct |
6 |
Correct |
51 ms |
71204 KB |
Output is correct |
7 |
Correct |
46 ms |
71200 KB |
Output is correct |
8 |
Correct |
46 ms |
71268 KB |
Output is correct |
9 |
Correct |
43 ms |
71168 KB |
Output is correct |
10 |
Correct |
44 ms |
71224 KB |
Output is correct |
11 |
Correct |
46 ms |
71244 KB |
Output is correct |
12 |
Correct |
51 ms |
71140 KB |
Output is correct |
13 |
Correct |
65 ms |
71228 KB |
Output is correct |
14 |
Correct |
47 ms |
71168 KB |
Output is correct |
15 |
Correct |
159 ms |
71272 KB |
Output is correct |
16 |
Correct |
46 ms |
71224 KB |
Output is correct |
17 |
Correct |
57 ms |
71244 KB |
Output is correct |
18 |
Correct |
72 ms |
71264 KB |
Output is correct |
19 |
Correct |
189 ms |
71220 KB |
Output is correct |
20 |
Correct |
171 ms |
71264 KB |
Output is correct |
21 |
Correct |
109 ms |
71252 KB |
Output is correct |
22 |
Correct |
118 ms |
71380 KB |
Output is correct |
23 |
Correct |
55 ms |
71276 KB |
Output is correct |
24 |
Correct |
288 ms |
71264 KB |
Output is correct |
25 |
Correct |
198 ms |
71276 KB |
Output is correct |
26 |
Correct |
223 ms |
71372 KB |
Output is correct |
27 |
Correct |
261 ms |
71344 KB |
Output is correct |