# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56847 |
2018-07-12T20:22:10 Z |
ksun48 |
Tents (JOI18_tents) |
C++14 |
|
1848 ms |
71416 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL powmod(LL a, LL n){
if(n == 0) return 1;
if(n % 2) return (a * powmod(a, n-1)) % MOD;
LL c = powmod(a, n/2);
return (c * c) % MOD;
}
LL inv(LL a){
return powmod(a, MOD-2);
}
LL fact[11000];
LL invfact[11000];
int main(){
LL a, b;
cin >> a >> b;
fact[0] = invfact[0] = 1;
for(LL i = 1; i < 11000; i++){
fact[i] = (i * fact[i-1]) % MOD;
invfact[i] = inv(fact[i]);
}
LL smth[a+1][b+1];
for(int i = 0; i <= a; i++){
for(int j = 0; j <= b; j++){
if(i == 0 || j == 0){
LL cur = 0;
for(int k = 0; k <= i && k <= j; k++){
LL z = powmod(4,k);
z = (z * invfact[k]) % MOD;
z = (z * invfact[i-k]) % MOD;
z = (z * invfact[j-k]) % MOD;
cur = (cur + z) % MOD;
}
cur = (cur * fact[i]) % MOD;
cur = (cur * fact[j]) % MOD;
smth[i][j] = cur;
} else {
smth[i][j] = smth[i-1][j] + (4 * j) * smth[i-1][j-1];
smth[i][j] %= MOD;
}
}
}
LL ans = 0;
for(LL c = 0; c <= a && c*2 <= b; c++){
for(LL d = 0; c + 2*d <= a && c*2 + d <= b; d++){
LL cur = (fact[a] * fact[b]) % MOD;
cur = (cur * inv(powmod(2,c))) % MOD;
cur = (cur * inv(powmod(2,d))) % MOD;
cur = (cur * invfact[c]) % MOD;
cur = (cur * invfact[d]) % MOD;
cur = (cur * invfact[a - c - 2*d]) % MOD;
cur = (cur * invfact[b - c*2 - d]) % MOD;
cur = (cur * smth[a - c - 2*d][b - c*2 - d]) % MOD;
ans = (ans + cur) % MOD;
}
}
ans--;
ans %= MOD;
if(ans < 0) ans += MOD;
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
620 KB |
Output is correct |
3 |
Correct |
6 ms |
620 KB |
Output is correct |
4 |
Correct |
6 ms |
668 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
9 ms |
816 KB |
Output is correct |
7 |
Correct |
10 ms |
948 KB |
Output is correct |
8 |
Correct |
7 ms |
948 KB |
Output is correct |
9 |
Correct |
7 ms |
948 KB |
Output is correct |
10 |
Correct |
10 ms |
976 KB |
Output is correct |
11 |
Correct |
6 ms |
976 KB |
Output is correct |
12 |
Correct |
18 ms |
1436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
620 KB |
Output is correct |
3 |
Correct |
6 ms |
620 KB |
Output is correct |
4 |
Correct |
6 ms |
668 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
9 ms |
816 KB |
Output is correct |
7 |
Correct |
10 ms |
948 KB |
Output is correct |
8 |
Correct |
7 ms |
948 KB |
Output is correct |
9 |
Correct |
7 ms |
948 KB |
Output is correct |
10 |
Correct |
10 ms |
976 KB |
Output is correct |
11 |
Correct |
6 ms |
976 KB |
Output is correct |
12 |
Correct |
18 ms |
1436 KB |
Output is correct |
13 |
Correct |
6 ms |
1436 KB |
Output is correct |
14 |
Correct |
6 ms |
1436 KB |
Output is correct |
15 |
Correct |
944 ms |
44600 KB |
Output is correct |
16 |
Correct |
19 ms |
44600 KB |
Output is correct |
17 |
Correct |
124 ms |
44600 KB |
Output is correct |
18 |
Correct |
254 ms |
44600 KB |
Output is correct |
19 |
Correct |
1255 ms |
52012 KB |
Output is correct |
20 |
Correct |
942 ms |
52012 KB |
Output is correct |
21 |
Correct |
584 ms |
52012 KB |
Output is correct |
22 |
Correct |
598 ms |
52012 KB |
Output is correct |
23 |
Correct |
128 ms |
52012 KB |
Output is correct |
24 |
Correct |
1848 ms |
71416 KB |
Output is correct |
25 |
Correct |
1261 ms |
71416 KB |
Output is correct |
26 |
Correct |
1271 ms |
71416 KB |
Output is correct |
27 |
Correct |
1494 ms |
71416 KB |
Output is correct |