QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65746 | #4843. Infectious Disease | Libf | AC ✓ | 4660ms | 504952kb | C++14 | 1.9kb | 2022-12-03 16:24:19 | 2022-12-03 16:24:28 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <cassert>
#define int long long
using namespace std ;
const int N = 2e7 + 5 , M = 2e5 + 5 , mod = 1e9 + 7 ;
namespace BINOM {
int inv[N] , ifac[N] , fac[N] ;
int binom_init(int n = N) {
inv[1] = fac[0] = ifac[0] = 1 ;
for (int i = 2 ; i < n ; ++ i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod ;
for (int i = 1 ; i < n ; ++ i) {
fac[i] = 1ll * fac[i - 1] * i % mod ;
ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod ;
}
return 0 ;
}
int get_binom = binom_init() ;
int C(int n , int m) {
if (n < m || m < 0) return 0 ;
return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod ;
}
}
using namespace BINOM ;
int qmi(int a , int b = mod - 2) {
int res = 1;
while (b) {
if (b & 1) res = (long long)res * a % mod;
a = (long long)a * a % mod , b >>= 1;
}
return res;
}
int n ;
int f[21][M] , pw[20] ;
void add(int &x , int y) { if ((x += y) >= mod) x -= mod ; }
// int cnt ;
int dfs(int i , int j) {
// ++ cnt ;
// assert(j >= 0) ;
if (f[i][j] != -1) return f[i][j] ;
if (j == 0) return 0 ;
int res = 1 ;
int x = min(n - pw[i] - j , j) , y = min(2 * pw[i] , n - pw[i]) ;
int tot = qmi(C(n - pw[i] , y)) ;
for (int t = 0 ; t <= min(j + x , y) ; ++ t) {
int fs = C(j + x , t) * C(n - pw[i] - j - x , y - t) % mod ;
fs = fs * tot % mod ;
if (fs)
add(res , fs * dfs(i + 1 , j + x - t) % mod) ;
}
return f[i][j] = res ;
}
signed main()
{
memset(f , -1 , sizeof f) ;
pw[0] = 1 ;
for (int i = 1 ; i < 20 ; ++ i) pw[i] = pw[i - 1] * 3 ;
cin >> n ;
cout << dfs(0 , 1) << '\n' ;
// cout << cnt << '\n' ;
return 0 ;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1798ms
memory: 504788kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1818ms
memory: 504824kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: 0
Accepted
time: 4540ms
memory: 504828kb
input:
14000000
output:
44565093
result:
ok 1 number(s): "44565093"
Test #4:
score: 0
Accepted
time: 4660ms
memory: 504844kb
input:
12345678
output:
123143093
result:
ok 1 number(s): "123143093"
Test #5:
score: 0
Accepted
time: 1794ms
memory: 504824kb
input:
776777
output:
764022068
result:
ok 1 number(s): "764022068"
Test #6:
score: 0
Accepted
time: 1685ms
memory: 504844kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 1693ms
memory: 504836kb
input:
4
output:
666666673
result:
ok 1 number(s): "666666673"
Test #8:
score: 0
Accepted
time: 1775ms
memory: 504828kb
input:
5
output:
833333341
result:
ok 1 number(s): "833333341"
Test #9:
score: 0
Accepted
time: 1661ms
memory: 504832kb
input:
6
output:
300000004
result:
ok 1 number(s): "300000004"
Test #10:
score: 0
Accepted
time: 1724ms
memory: 504840kb
input:
7
output:
533333339
result:
ok 1 number(s): "533333339"
Test #11:
score: 0
Accepted
time: 1634ms
memory: 504832kb
input:
8
output:
952380961
result:
ok 1 number(s): "952380961"
Test #12:
score: 0
Accepted
time: 1644ms
memory: 504828kb
input:
9
output:
964285723
result:
ok 1 number(s): "964285723"
Test #13:
score: 0
Accepted
time: 1645ms
memory: 504836kb
input:
10
output:
416666672
result:
ok 1 number(s): "416666672"
Test #14:
score: 0
Accepted
time: 1727ms
memory: 504892kb
input:
26
output:
990086590
result:
ok 1 number(s): "990086590"
Test #15:
score: 0
Accepted
time: 1675ms
memory: 504952kb
input:
27
output:
528360342
result:
ok 1 number(s): "528360342"
Test #16:
score: 0
Accepted
time: 1752ms
memory: 504860kb
input:
28
output:
273239648
result:
ok 1 number(s): "273239648"
Test #17:
score: 0
Accepted
time: 2288ms
memory: 504848kb
input:
4782967
output:
332194401
result:
ok 1 number(s): "332194401"
Test #18:
score: 0
Accepted
time: 2406ms
memory: 504860kb
input:
4782968
output:
362625027
result:
ok 1 number(s): "362625027"
Test #19:
score: 0
Accepted
time: 2380ms
memory: 504872kb
input:
4782969
output:
971032452
result:
ok 1 number(s): "971032452"
Test #20:
score: 0
Accepted
time: 2418ms
memory: 504820kb
input:
4782970
output:
452836984
result:
ok 1 number(s): "452836984"
Test #21:
score: 0
Accepted
time: 2401ms
memory: 504836kb
input:
4782971
output:
349324970
result:
ok 1 number(s): "349324970"
Test #22:
score: 0
Accepted
time: 2421ms
memory: 504836kb
input:
4782972
output:
46862963
result:
ok 1 number(s): "46862963"
Test #23:
score: 0
Accepted
time: 1938ms
memory: 504840kb
input:
114514
output:
972669965
result:
ok 1 number(s): "972669965"
Test #24:
score: 0
Accepted
time: 2428ms
memory: 504840kb
input:
1919810
output:
482430785
result:
ok 1 number(s): "482430785"
Test #25:
score: 0
Accepted
time: 4328ms
memory: 504820kb
input:
8877877
output:
486769120
result:
ok 1 number(s): "486769120"