QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65771#4843. Infectious DiseasesoarskyTL 165ms237848kbC++202.0kb2022-12-03 16:44:542022-12-03 16:44:56

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 16:44:56]
  • 评测
  • 测评结果:TL
  • 用时:165ms
  • 内存:237848kb
  • [2022-12-03 16:44:54]
  • 提交

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


int main(void){
    int n;
    cin >> n;
    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); //最多感染的人
    // cerr << inft << '\n';
    for(int i = 0; i < da; ++i){
        for(int j = 1; j <= inft; ++j){
            if(dp[i][j] == 0)continue;
            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 * invs(C(n - vac, cure)) % p) % p;
                // cerr << dp[i + 1][k] << ' ' << i + 1 << ' ' << k << '\n';
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= da; ++i)ans = (ans + dp[i][0] * i) % p;
    cout << ans << '\n';
    // cerr << invs(C(n - 1, 2)) % p;
}

詳細信息

Test #1:

score: 100
Accepted
time: 165ms
memory: 237848kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: -100
Time Limit Exceeded

input:

14000000

output:


result: