# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56611 |
2018-07-12T03:22:19 Z |
ksun48 |
Tents (JOI18_tents) |
C++14 |
|
2000 ms |
3848 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++){
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;
}
smth[i][j] = cur;
}
}
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 * 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 |
8 ms |
692 KB |
Output is correct |
2 |
Correct |
8 ms |
692 KB |
Output is correct |
3 |
Correct |
8 ms |
736 KB |
Output is correct |
4 |
Correct |
6 ms |
920 KB |
Output is correct |
5 |
Correct |
31 ms |
1020 KB |
Output is correct |
6 |
Correct |
45 ms |
1152 KB |
Output is correct |
7 |
Correct |
60 ms |
1152 KB |
Output is correct |
8 |
Correct |
24 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1152 KB |
Output is correct |
10 |
Correct |
159 ms |
1268 KB |
Output is correct |
11 |
Correct |
8 ms |
1268 KB |
Output is correct |
12 |
Correct |
704 ms |
2064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
692 KB |
Output is correct |
2 |
Correct |
8 ms |
692 KB |
Output is correct |
3 |
Correct |
8 ms |
736 KB |
Output is correct |
4 |
Correct |
6 ms |
920 KB |
Output is correct |
5 |
Correct |
31 ms |
1020 KB |
Output is correct |
6 |
Correct |
45 ms |
1152 KB |
Output is correct |
7 |
Correct |
60 ms |
1152 KB |
Output is correct |
8 |
Correct |
24 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1152 KB |
Output is correct |
10 |
Correct |
159 ms |
1268 KB |
Output is correct |
11 |
Correct |
8 ms |
1268 KB |
Output is correct |
12 |
Correct |
704 ms |
2064 KB |
Output is correct |
13 |
Correct |
7 ms |
2064 KB |
Output is correct |
14 |
Correct |
8 ms |
2064 KB |
Output is correct |
15 |
Execution timed out |
2064 ms |
3848 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |