QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65836 | #4843. Infectious Disease | MuYun | AC ✓ | 1830ms | 114668kb | C++14 | 1.9kb | 2022-12-03 19:28:19 | 2022-12-03 19:28:23 |
Judging History
answer
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define PB emplace_back
// #define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int)((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 1.4e7, mod = 1e9 + 7;
int a, f[2][N + 5];
ll pw[31];
int fac[N + 5], inv[N + 5];
int qp(int n, int m = mod - 2) {
int res = 1;
for (; m; m >>= 1) {
if (m & 1) res = 1ll * res * n % mod;
n = 1ll * n * n % mod;
}
return res;
}
void init() {
fac[0] = fac[1] = 1;
rep(i, 2, N) fac[i] = 1ll * fac[i - 1] * i % mod;
inv[N] = qp(fac[N]);
per(i, N - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) { return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod; }
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
init();
cin >> a;
f[0][1] = 1;
pw[0] = 1;
rep(i, 1, 30) {
pw[i] = pw[i - 1] * 3 % mod;
if (pw[i] > 1e9) break;
}
int ans = 0;
rep(i, 0, 30) {
(ans += 1ll * f[i & 1][0] * i % mod) %= mod;
f[i & 1][0] = 0;
if (pw[i] > a) break;
int cnt = pw[i];
rep(j, 1, a) {
if (!f[i & 1][j]) continue;
if (pw[i + 1] >= a) {
(f[(i & 1) ^ 1][0] += f[i & 1][j]) %= mod;
continue;
}
int k = min(a - cnt, 2 * j), b = a - cnt, w = qp(C(b, 2 * cnt));
rep(p, max(0, 2 * cnt - b + k), min(k, 2 * cnt)) {
int q = 2 * cnt - p;
if (q < 0 || q > b - k) assert(0);
(f[(i & 1) ^ 1][k - p] += 1ll * f[i & 1][j] * C(k, p) % mod * C(b - k, q) % mod * w % mod) %= mod;
}
f[i & 1][j] = 0;
}
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 155ms
memory: 112680kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 152ms
memory: 113456kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 1830ms
memory: 113996kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 1811ms
memory: 113256kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 275ms
memory: 114380kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 160ms
memory: 113116kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 145ms
memory: 114028kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 152ms
memory: 114460kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 138ms
memory: 114632kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 164ms
memory: 114276kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 151ms
memory: 114180kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 155ms
memory: 113168kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 144ms
memory: 114636kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 152ms
memory: 114668kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 159ms
memory: 114084kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 147ms
memory: 114024kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 632ms
memory: 113200kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 660ms
memory: 114524kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 603ms
memory: 113760kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 661ms
memory: 112756kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 652ms
memory: 113368kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 638ms
memory: 114040kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 151ms
memory: 114572kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 515ms
memory: 113104kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 1695ms
memory: 114416kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"