QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65744 | #4843. Infectious Disease | clf123456 | AC ✓ | 1680ms | 302124kb | C++14 | 1.1kb | 2022-12-03 16:24:02 | 2022-12-03 16:24:04 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e7+5e6;
const int mod=1e9+7;
int jc[maxn],inv[maxn],n;
signed dp[1000000][16];
int mp[maxn];
int C(int n,int m){
return jc[n]*inv[n-m]%mod*inv[m]%mod;
}
int ksm(int x,int p,int mod){
int ans=1;
while(p){
if(p&1) ans=ans*x%mod;
x=x*x%mod;
p>>=1;
}
return ans;
}
int dfs(int x,int y){
if(x==0) return 0;
if(dp[x][y]!=-1) return dp[x][y];
int r=min(2*x,n-y);
int z=min(2*y,n-y);
int sum=n-y;
int mn=max(0LL,r+z-sum);
int mx=min(r,z);
int ans=1;
int fm=ksm(C(n-y,z),mod-2,mod);
for(int i=mn;i<=mx;i++){
ans+=C(r,i)*C(n-y-r,z-i)%mod*dfs(r-i,z+y)%mod*fm%mod;
ans%=mod;
}
return dp[x][y]=ans;
}
void init(){
jc[0]=inv[0]=1;
for(int i=1;i<maxn;i++) jc[i]=i*jc[i-1]%mod;
inv[maxn-1]=ksm(jc[maxn-1],mod-2,mod);
for(int i=maxn-2;i>=1;i--){
inv[i]=(i+1)*inv[i+1]%mod;
}
mp[1]=0;
int base=3;
for(int i=1;;i++){
if(base>=n){
mp[n]=i;
break;
}
mp[base]=i;
base*=3;
}
}
signed main(){
memset(dp,-1,sizeof(dp));
init();
int base=1;
cin>>n;
cout<<dfs(1,1)<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 160ms
memory: 301436kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 158ms
memory: 300492kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1636ms
memory: 301404kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1680ms
memory: 300580kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 277ms
memory: 301488kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 167ms
memory: 300732kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 151ms
memory: 300284kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 214ms
memory: 302124kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 162ms
memory: 301988kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 191ms
memory: 301616kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 165ms
memory: 301048kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 190ms
memory: 301608kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 176ms
memory: 300840kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 169ms
memory: 300492kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 206ms
memory: 300772kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 193ms
memory: 300332kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 533ms
memory: 300808kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 576ms
memory: 301836kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 510ms
memory: 301220kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 578ms
memory: 300216kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 548ms
memory: 301396kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 582ms
memory: 301492kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 199ms
memory: 300584kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 604ms
memory: 300396kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1678ms
memory: 300496kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"