QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#58029 | #4843. Infectious Disease | MIT01# | AC ✓ | 1146ms | 224648kb | C++ | 2.0kb | 2022-10-24 11:00:32 | 2022-10-24 11:00:34 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define mod 1000000007
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
using namespace std;
const int maxn = 14000005;
const int S = 50;
const int D = 300005;
int n;
ll p[S][D];
ll jc[maxn], bjc[maxn];
ll c(int a, int b) {
if (b < 0) return 0;
if (b > a) return 0;
return jc[a] * bjc[b] % mod * bjc[a - b] % mod;
}
ll bc(int a, int b) {
if (b < 0)
return 0;
if (b > a)
return 0;
return bjc[a] * jc[b] % mod * jc[a - b] % mod;
}
int main() {
jc[0] = 1;
for (int i = 1; i < maxn; i++) jc[i] = jc[i - 1] * i % mod;
bjc[maxn - 1] = ksm(jc[maxn - 1], mod - 2);
for (int i = maxn - 2; i >= 0; i--)
bjc[i] = bjc[i + 1] * (i + 1) % mod;
int n;
cin >> n;
p[0][1] = 1;
int good = 1;
ll ans = 0;
for (int i = 1; i < S; i++) {
int rem = n - good;
if (rem == 0) break;
good *= 3;
chkmin(good, n);
int newrem = n - good;
for (int k = 0; k < D; k++) {
if (p[i - 1][k]) {
int nw = min(2 * k, rem);
assert(nw < D);
for (int j = 0; j <= min(nw, newrem); j++)
p[i][j] = (p[i][j] + 1ll * p[i - 1][k] * c(nw, j) % mod * c(rem - nw, newrem - j) % mod * bc(rem, newrem)) % mod;
}
}
// cout << bg << endl;
for (int k = 1; k < D; k++)
ans = (ans + p[i][k]) % mod;
}
ans = (ans + 1) % mod;
cout << ans << endl;
return 0;
}
/*
1
1.6666 (5/3)
1.8333 (11/6)
1.9 (19/10)
1.9333 (29/15)
1.95238 (41/21)
1.96154 (55/28)
2.41667 = 29/12
2.63175 = 41/15
*/
详细
Test #1:
score: 100
Accepted
time: 131ms
memory: 222480kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 160ms
memory: 222496kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1138ms
memory: 222716kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1117ms
memory: 222568kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 220ms
memory: 222424kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 126ms
memory: 222260kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 141ms
memory: 222444kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 130ms
memory: 222316kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 161ms
memory: 222316kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 141ms
memory: 222436kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 138ms
memory: 222436kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 145ms
memory: 222432kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 112ms
memory: 222336kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 144ms
memory: 222208kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 146ms
memory: 222400kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 144ms
memory: 222448kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 358ms
memory: 222484kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 420ms
memory: 224448kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 393ms
memory: 222568kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 416ms
memory: 222588kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 405ms
memory: 222528kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 407ms
memory: 222448kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 155ms
memory: 222364kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 450ms
memory: 224648kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1146ms
memory: 224644kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"