QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65830 | #4843. Infectious Disease | Uaena | AC ✓ | 1966ms | 239800kb | C++17 | 1.8kb | 2022-12-03 19:02:12 | 2022-12-03 19:02:16 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9+7,N = 15e6+10;
int in[N],inv[N];
int dp[20][50005];
int qmi(int a,int k)
{
int res = 1;
while(k)
{
if(k&1) res = res*a%mod;
a = a*a%mod;
k>>=1;
}
return res;
}
int get(int n)
{
int l = 1, r = 400;
while(l<r)
{
int mid = l+r>>1;
if(qmi(3,mid)>=n)
{
r = mid;
}
else l = mid+1;
}
return l;
}
void init()
{
in[0] = inv[0] = 1;
for(int i=1;i<N;i++) in[i] = in[i-1] * i % mod;
inv[N-1] = qmi(in[N-1],mod-2);
for(int i=N-2;i>=1;i--)
{
inv[i] = inv[i+1] * (i+1) % mod;
}
}
int C(int a,int b)
{
if(b>a || a<0 || b<0) return 0;
return in[a] * inv[b] % mod * inv[a-b] % mod;
}
int inC(int a,int b)
{
if(b>a || b<0 || a<0) return 0;
return inv[a] * in[b] % mod * in[a-b]%mod;
}
signed main()
{
init();
int n; cin>>n;
dp[0][1] = 1; //前i天A集合中元素个数为j的概率
int da = get(n); // 最多执行几天
int inft = qmi(2,da-1);
for(int i=0;i<da;i++)
{
for(int j=1;j<=inft;j++) //枚举A集合的元素个数
{
if(dp[i][j]==0) break;
int vac = qmi(3,i); // 第i天的接种总人数
int infd = min(n-vac,2*j); //第i天被感染的总人数。
int cure = min(n-vac,2*vac); // 第i天被接种人数
for(int k=0;k<=min(infd,n-vac-cure);k++)
{
dp[i+1][k] = (dp[i+1][k] + dp[i][j] * (C(infd,infd-k) * C(n-vac-infd,cure-infd+k) % mod) % mod * inC(n-vac,cure) % mod) % mod;
}
}
}
int ans = 0;
for(int i=1;i<=da;i++) ans = (ans + dp[i][0] * i) % mod;
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 181ms
memory: 238852kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 166ms
memory: 237684kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1934ms
memory: 239404kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1961ms
memory: 238292kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 261ms
memory: 238952kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 205ms
memory: 237684kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 189ms
memory: 238848kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 155ms
memory: 238348kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 151ms
memory: 239460kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 162ms
memory: 239168kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 149ms
memory: 239220kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 193ms
memory: 238160kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 169ms
memory: 238680kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 125ms
memory: 238160kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 163ms
memory: 239508kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 171ms
memory: 237968kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 624ms
memory: 239152kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 681ms
memory: 239272kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 676ms
memory: 239424kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 601ms
memory: 239244kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 593ms
memory: 239208kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 627ms
memory: 238648kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 189ms
memory: 238732kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 608ms
memory: 239800kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1966ms
memory: 238584kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"