QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65787#4843. Infectious DiseasesoarskyAC ✓2048ms239748kbC++202.3kb2022-12-03 17:09:512022-12-03 17:09:53

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:09:53]
  • 评测
  • 测评结果:AC
  • 用时:2048ms
  • 内存:239748kb
  • [2022-12-03 17:09:51]
  • 提交

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: 171ms
memory: 237712kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 187ms
memory: 239300kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 2018ms
memory: 238084kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 1965ms
memory: 238588kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 270ms
memory: 238932kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 163ms
memory: 238072kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 137ms
memory: 238196kb

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 141ms
memory: 238304kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

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

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 153ms
memory: 238580kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 136ms
memory: 238552kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 169ms
memory: 237772kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 152ms
memory: 239040kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 179ms
memory: 237964kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

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

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 172ms
memory: 238948kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 613ms
memory: 237816kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 632ms
memory: 239152kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 677ms
memory: 237820kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 664ms
memory: 239748kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 639ms
memory: 239100kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 641ms
memory: 239708kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 184ms
memory: 237708kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 690ms
memory: 238920kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 2048ms
memory: 239116kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"