QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65845#4843. Infectious DiseaseyezzzAC ✓1665ms316220kbC++171.9kb2022-12-03 19:45:402022-12-03 19:45:41

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 19:45:41]
  • 评测
  • 测评结果:AC
  • 用时:1665ms
  • 内存:316220kb
  • [2022-12-03 19:45:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int,int>
using namespace std;

const int mo=1e9+7, N=2e7+5;
int dp[17][400005];
int ksm(int a,int b=mo-2)
{
    int res=1;
    while(b)
    {
        if(b&1) res=res*a%mo;
        a=a*a%mo; b>>=1;
    }
    return res;
}
int fac[N], inv[N];
void init()
{
    fac[0]=inv[0]=1;
    int m=2e7;
    for(int i=1;i<=m;i++) fac[i]=fac[i-1]*i%mo;
    inv[m]=ksm(fac[m]);
    for(int i=m-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mo;
}
int C(int n,int m)
{
    if(m>n || m<0 || n<0) return 0;
    return fac[n]*inv[m]%mo*inv[n-m]%mo;
}
void solve(){
    init();
    int n; cin>>n;
    int cnt=0, t=1;
    while(t<n) t*=3, cnt++;
    dp[0][1]=1;
    // dp[1][2]=
    int mxj=1,mxc=1;
    for(int i=1;i<cnt;i++)
    {
        mxj*=2;
        for(int j=0;j<=mxj;j++)
        {
            int sum=n-mxc, c=2*mxc;
            int tmp=ksm(C(sum,c));
            for(int k=max((j+1)/2,1ll);k<=mxj/2;k++)
            {
                // cout<<i<<' '<<j<<' '<<k<<" ???\n";
                dp[i][j]+=dp[i-1][k]*C(2*k,j)%mo*C(sum-2*k,c-(2*k-j))%mo*tmp%mo;
                dp[i][j]%=mo;
            }
            // cout<<i<<' '<<j<<' '<<dp[i][j]<<"\n";
        }
        mxc*=3;
    } 
    int ans=0;
    // cout<<dp[2][0]<<"\n";
    // for(int i=1;i<=1000;i++) if(i*ksm(36)%mo==dp[2][0]) cout<<i<<"\n";
    // cout<<dp[2][0]<<' '<<35*ksm(36)%mo<<"\n";
    for(int i=1;i<cnt;i++) (ans+=i*dp[i][0]%mo)%=mo;
    // cout<<ans<<"\n";
    // cout<<39*ksm(36)%mo<<"\n";
    for(int i=1;i<=ksm(2,cnt+1);i++) (ans+=cnt*dp[cnt-1][i]%mo)%=mo;
    cout<<ans<<'\n';
    // for(int i=1;i<=500;i++) if(i*ksm(36)%mo==ans) cout<<i<<"\n";
    // cout<<ans<<"\n";
    // cout<<87*ksm(36)%mo<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 221ms
memory: 315904kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 260ms
memory: 315932kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 1639ms
memory: 316188kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 1657ms
memory: 316028kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 346ms
memory: 315988kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 220ms
memory: 315792kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 216ms
memory: 315908kb

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 228ms
memory: 315820kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 220ms
memory: 315792kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 249ms
memory: 315720kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 275ms
memory: 315784kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 237ms
memory: 315920kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 221ms
memory: 315728kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 210ms
memory: 315824kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 230ms
memory: 315820kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 225ms
memory: 315732kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 623ms
memory: 315956kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 614ms
memory: 315984kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 599ms
memory: 315992kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 1027ms
memory: 316100kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 1060ms
memory: 316096kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 1032ms
memory: 316220kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 235ms
memory: 315828kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 588ms
memory: 316052kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 1665ms
memory: 316108kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"