QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65857 | #4843. Infectious Disease | Nebula_xuan | AC ✓ | 1966ms | 231520kb | C++14 | 1.1kb | 2022-12-03 21:04:55 | 2022-12-03 21:04:57 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1.4e7 + 10, MOD = 1e9 + 7;
int n;
int f[40000][30], jc[N], inv[N];
int power(int a, int b) {
int ans = 1;
for(; b; b >>= 1) {
if(b & 1) ans = ans * a % MOD;
a = a * a % MOD;
}
return ans;
}
int C(int n, int m) {
if(n < m) return 0;
return jc[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int dfs(int a, int b, int u) {
if(b >= n || a == 0) return 0;
if(f[a][u] != -1) return f[a][u];
int res = 1, da = min(n - a - b, a), db = min(n - b, 2 * b), cnt = C(n - b, db);
int tt = power(cnt, MOD - 2);
for(int i = max(0ll, db - (n - b - a - da)); i <= min(db, a + da); i++) {
res = (res + C(a + da, i) * C(n - b - a - da, (db - i)) % MOD * tt % MOD * dfs(a + da - i, b + db, u + 1)) % MOD;
}
return f[a][u] = res;
}
signed main() {
jc[0] = inv[0] = 1;
for(int i = 1; i < N; i++) jc[i] = jc[i - 1] * i % MOD;
inv[N - 1] = power(jc[N - 1], MOD - 2);
for(int i = N - 2; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
memset(f, -1, sizeof(f));
cin >> n;
cout << dfs(1, 1, 0) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 181ms
memory: 231380kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 150ms
memory: 231400kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1877ms
memory: 231392kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1966ms
memory: 231392kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 290ms
memory: 231396kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 151ms
memory: 231488kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 150ms
memory: 231512kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 139ms
memory: 231520kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 191ms
memory: 231400kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 170ms
memory: 231488kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 167ms
memory: 231384kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 145ms
memory: 231348kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 185ms
memory: 231424kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 175ms
memory: 231392kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 172ms
memory: 231348kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 129ms
memory: 231380kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 564ms
memory: 231508kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 549ms
memory: 231328kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 563ms
memory: 231516kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 556ms
memory: 231400kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 609ms
memory: 231428kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 553ms
memory: 231328kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 159ms
memory: 231396kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 540ms
memory: 231416kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1902ms
memory: 231392kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"