QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65788#4843. Infectious DiseasesoarskyAC ✓1788ms239656kbC++202.3kb2022-12-03 17:10:312022-12-03 17:10:32

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 17:10:32]
  • 评测
  • 测评结果:AC
  • 用时:1788ms
  • 内存:239656kb
  • [2022-12-03 17:10:31]
  • 提交

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;
}

详细

Test #1:

score: 100
Accepted
time: 172ms
memory: 238552kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 171ms
memory: 237780kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 1759ms
memory: 238720kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 1758ms
memory: 237992kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 223ms
memory: 237700kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 171ms
memory: 238524kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 177ms
memory: 237660kb

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 177ms
memory: 237656kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 166ms
memory: 238112kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 165ms
memory: 237836kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 162ms
memory: 239656kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 146ms
memory: 239472kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 174ms
memory: 237600kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 167ms
memory: 237664kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 168ms
memory: 237824kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 160ms
memory: 238848kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 563ms
memory: 237836kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 553ms
memory: 237948kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 534ms
memory: 237756kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 569ms
memory: 238592kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 565ms
memory: 239244kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 539ms
memory: 237824kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 161ms
memory: 238168kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 582ms
memory: 237764kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 1788ms
memory: 237956kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"