QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65789 | #4843. Infectious Disease | soarsky | AC ✓ | 1733ms | 239796kb | C++20 | 2.3kb | 2022-12-03 17:16:37 | 2022-12-03 17:16:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void err(){
cerr << '\n';
}
template<typename T, typename ...Args>
void err(T a, Args... args){
cerr << a << ' ';
err(args...);
}
const int N = 15e6;
ll dp[20][50005];
ll fac[N], inv[N];
const int p = 1e9 + 7;
ll qpow(ll x, ll y){
ll res = 1;
for(; x && y; x = x * x % p, y >>= 1){
if(y & 1)res = res * x % p;
}
return res;
}
ll get(int n){
int l = 1, r = 400;
while(l < r){
int mid = l + r >> 1;
if(qpow(3, mid) >= n){
r = mid;
}else{
l = mid + 1;
}
}
return l;
}
ll invs(ll x){
return qpow(x % p, p - 2);
}
ll C(int n, int m){
if(m > n || m < 0)return 0;
return fac[n] * inv[m] % p * inv[n - m] % p;
}
ll inC(int n, int m){
if(m > n || m < 0)return 0;
return fac[m] * fac[n - m] % p * inv[n] % p;
}
int main(void){
int n;
cin >> n;
// if(n == 14000000){
// cout << 44565093 << '\n';
// return 0;
// }
fac[0] = 1;
for(int i = 1; i < N; ++i)fac[i] = fac[i - 1] * i % p;
inv[N - 1] = invs(fac[N - 1]);
for(int i = N - 1; i; --i)inv[i - 1] = inv[i] * i % p;
dp[0][1] = 1;
int da = get(n);
int inft = qpow(2, da - 1); //最多感染的人
// int cnt = 0;
// cerr << inft << '\n';
for(int i = 0; i < da; ++i){
for(int j = 1; j <= inft; ++j){
if(dp[i][j] == 0)break;
int vac = qpow(3, i); //接种
int infd = min(n - vac, 2 * j); //已经被感染的人,等待被治疗
int cure = min(n - vac, 2 * vac);
for(int k = 0; k <= min(infd, n - vac - cure); ++k){
// err(infd, k, infd - k, n - vac - infd, cure - infd + k, n - vac, cure);
dp[i + 1][k] = (dp[i + 1][k] + dp[i][j] * (C(infd, infd - k) * C(n - vac - infd, cure - infd + k) % p) % p * inC(n - vac, cure) % p) % p;
// cerr << dp[i + 1][k] << ' ' << i + 1 << ' ' << k << '\n';
// cnt++;
}
}
}
ll ans = 0;
for(int i = 1; i <= da; ++i)ans = (ans + dp[i][0] * i) % p;
// err(cnt);
cout << ans << '\n';
// cerr << invs(C(n - 1, 2)) % p;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 139ms
memory: 237916kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 157ms
memory: 239480kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1733ms
memory: 239568kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1717ms
memory: 238772kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 263ms
memory: 238820kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 167ms
memory: 239592kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 164ms
memory: 238100kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 157ms
memory: 239796kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 173ms
memory: 237776kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 143ms
memory: 238308kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 160ms
memory: 238988kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 155ms
memory: 237992kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 148ms
memory: 237744kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 168ms
memory: 237644kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 142ms
memory: 237648kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 186ms
memory: 237648kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 605ms
memory: 237952kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 550ms
memory: 237836kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 563ms
memory: 237864kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 537ms
memory: 237952kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 564ms
memory: 238284kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 556ms
memory: 238708kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 166ms
memory: 239320kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 546ms
memory: 237764kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1714ms
memory: 238420kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"