QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65854 | #4843. Infectious Disease | Kkskr | AC ✓ | 1350ms | 222476kb | C++14 | 1.7kb | 2022-12-03 20:22:20 | 2022-12-03 20:22:24 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
const int N = 14000005;
const int mod = 1000000007;
int n;
int fac[N], ifac[N];
int dp[16][65537];
int qpow(int a, int b = mod - 2) {
int res = 1;
for (; b; b >>= 1) {
if(b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
}
return res;
}
int C(int n, int m) {
if(m > n) return 0;
return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
fac[0] = 1;
for (int i = 1; i < N; i++) fac[i] = 1ll * i * fac[i - 1] % mod;
ifac[N - 1] = qpow(fac[N - 1]);
for (int i = N - 1; i; i--) ifac[i - 1] = 1ll * ifac[i] * i % mod;
dp[0][1] = 1;
for (int i = 1; i <= 15; i++) {
int vac = qpow(3, i - 1);
int v = qpow(3, i) - qpow(3, i - 1);
int t1 = qpow(C(n - vac, v));
if(n - vac <= v) {
for (int j = 1; j <= (1 << i - 1); j++)
dp[i][0] = (dp[i][0] + dp[i - 1][j]) % mod;
break;
}
// for (int j = 0; j <= (1 << i); j++) { // 感染的人数
// for (int k = max(1ll, (j + 1) >> 1); k <= (1 << i - 1); k++) { //
// int l = 2 * k - j; // 感染者中选择接种的数量
// dp[i][j] = (dp[i][j] + 1ll * dp[i - 1][k] * t1 % mod * C(k * 2, l) % mod * C(n - k * 2 - vac, v - l) % mod) % mod;
// assert(k <= n);
// }
// }
for (int j = 1; j <= (1 << i - 1); j++) if(dp[i - 1][j]) {
for (int k = 0; k <= j * 2; k++) {
int l = 2 * j - k;
dp[i][k] = (dp[i][k] + 1ll * dp[i - 1][j] * t1 % mod * C(j * 2, l) % mod * C(n - vac - j * 2, v - l) % mod) % mod;
}
}
}
int ans = 0;
for (int i = 1; i <= 15; i++) ans = (ans + 1ll * dp[i][0] * i) % mod;
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 156ms
memory: 222052kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 148ms
memory: 222116kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1350ms
memory: 222368kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1350ms
memory: 222296kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 225ms
memory: 222280kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 145ms
memory: 222044kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 156ms
memory: 222064kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 159ms
memory: 222064kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 171ms
memory: 222176kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 158ms
memory: 222040kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 185ms
memory: 222040kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 157ms
memory: 222084kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 152ms
memory: 222088kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 159ms
memory: 222092kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 151ms
memory: 221992kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 163ms
memory: 222072kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 472ms
memory: 222164kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 456ms
memory: 222232kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 463ms
memory: 222228kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 941ms
memory: 222472kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 1005ms
memory: 222296kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 947ms
memory: 222340kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 168ms
memory: 222136kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 403ms
memory: 222216kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1313ms
memory: 222476kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"