QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65863#4843. Infectious DiseasemyeeAC ✓912ms332532kbC++141.9kb2022-12-03 21:53:032022-12-03 21:53:07

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 21:53:07]
  • 评测
  • 测评结果:AC
  • 用时:912ms
  • 内存:332532kb
  • [2022-12-03 21:53:03]
  • 提交

answer

#ifdef MYEE
#pragma GCC optimize("-O2")
#endif

#include <bits/stdc++.h>
using uint = unsigned;
using ullt = unsigned long long;
const ullt Mod=1e9+7;
struct modint{
    ullt v;
    modint():v(0){}
    modint(ullt v):v(v%Mod){}
    ullt&operator()(){return v;}
    friend modint operator+(modint a,modint b){return a()+b();}
    friend modint operator-(modint a,modint b){return a()+Mod-b();}
    friend modint operator*(modint a,modint b){return a()*b();}
    friend modint operator^(modint a,ullt b){
        modint ans(1);
        while(b){
            if(b&1)ans*=a;
            a*=a,b>>=1;
        }
        return ans;
    }
    modint inv(){return*this^(Mod-2);}
    modint operator+=(modint b){return*this=*this+b;}
    modint operator-=(modint b){return*this=*this-b;}
    modint operator*=(modint b){return*this=*this*b;}
    void println(){printf("%llu\n",v);}
};
modint P[20000005],Q[20000005];
modint Dp[1u<<20|1],Last[1u<<20|1];
int main(){
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
#endif
    P[0]=1;for(uint i=1;i<=20000000;i++)P[i]=P[i-1]*i;
    Q[20000000]=P[20000000].inv();for(uint i=20000000;i;i--)Q[i-1]=Q[i]*i;
    uint n;scanf("%u",&n);
    Dp[1]=1;uint cnt2=1,cnt3=1;
    modint ans;
    for(uint k=1;cnt3<=n;k++){
        if(cnt3*3>=n){
            for(uint i=1;i<=cnt2;i++)ans+=Dp[i]*k;
            break;
        }
        uint A=n-cnt3,B=2*cnt3;
        for(uint i=1;i<=cnt2*2;i++)Last[i]=0;
        for(uint i=1;i<=cnt2;i++)
            Last[std::min(n-cnt3,i*2)]+=Dp[i],Dp[i]=0;
        cnt2*=2;
        for(uint m=1;m<=cnt2;m++){
            modint v=Last[m]*P[m]*P[A-m];
            for(uint t=std::min(m,B);~t&&A+t>=B+m;t--)
                Dp[m-t]+=v*Q[t]*Q[B-t];
        }
        for(uint m=0;m<=cnt2&&m+B<=A;m++)
            Dp[m]*=Q[A]*P[B]*P[A-B]*Q[m]*Q[A-B-m];
        ans+=Dp[0]*k,Dp[0]=0;
        cnt3*=3;
    }
    ans.println();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 285ms
memory: 332340kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 218ms
memory: 332352kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 894ms
memory: 332352kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 894ms
memory: 332344kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 295ms
memory: 332500kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 217ms
memory: 332424kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 264ms
memory: 332352kb

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 246ms
memory: 332372kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 251ms
memory: 332396kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 233ms
memory: 332340kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 254ms
memory: 332508kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 246ms
memory: 332364kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 246ms
memory: 332356kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 272ms
memory: 332396kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 238ms
memory: 332364kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

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

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 402ms
memory: 332344kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 419ms
memory: 332504kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 433ms
memory: 332364kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 435ms
memory: 332420kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 387ms
memory: 332532kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 404ms
memory: 332424kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 240ms
memory: 332508kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 401ms
memory: 332344kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 912ms
memory: 332376kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"