QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#96674 | #5586. Digits of Unity | Nicolas125841 | AC ✓ | 3592ms | 120084kb | C++14 | 2.3kb | 2023-04-15 01:08:33 | 2023-04-15 01:08:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
vector<ll> fac(5000011, 0), ifac(5000011, 0), inv(5000011, 0);
ll perm(int n, int k){
return fac[n] * ifac[n-k] % mod;
}
ll comb(int n, int k){
return ((fac[n] * ifac[k]) % mod) * ifac[n-k] % mod;
}
int main(){
cin.tie(NULL)->sync_with_stdio(false);
fac[0] = fac[1] = 1;
ifac[0] = ifac[1] = 1;
inv[0] = inv[1] = 1;
for(ll i = 2; i <= 5000000; i++){
inv[i] = mod - (mod/i) * inv[mod%i] % mod;
fac[i] = i * fac[i-1] % mod;
ifac[i] = inv[i] * ifac[i-1] % mod;
}
int n, k, m;
cin >> n >> k >> m;
int ml = 0;
while((1<<ml) <= m)
ml++;
ll ans = 0;
vector<ll> weights(23, 0);
for(int i = k; i < 23; i++){
ll weight = 0;
for(int j = k; j < i; j++){
weight += weights[j] * comb(i, j) % mod;
weight %= mod;
}
weight = 1 - weight;
weight %= mod;
if(weight < 0)
weight += mod;
weights[i] = weight;
}
for(int i = 0; i <= m; i++){
if(__builtin_popcount(i) >= k){
vector<vector<ll>> dp(ml, vector<ll>(3, 0));
dp[ml-1][2] = 1;
if((i & (1<<(ml-1))) == 0)
dp[ml-1][0] = 1;
for(int j = ml-2; j >= 0; j--){
if(m & (1<<j)){
dp[j][2] = dp[j+1][2];
dp[j][1] = dp[j+1][0] + dp[j+1][1];
if((i & (1<<j)) == 0){
dp[j][0] = dp[j+1][0] + dp[j+1][1] + dp[j+1][2];
}
}else{
dp[j][1] = dp[j+1][0] + dp[j+1][1];
if((i & (1<<j)) == 0){
dp[j][2] = dp[j+1][2];
dp[j][0] = dp[j+1][0] + dp[j+1][1];
}
}
}
int mx = dp[0][0] + dp[0][1] + dp[0][2];
if(mx >= n){
ans += weights[__builtin_popcount(i)] * perm(mx, n) % mod;
ans %= mod;
if(ans < 0)
ans += mod;
}
}
}
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 203ms
memory: 119956kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 197ms
memory: 119952kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 284ms
memory: 119928kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: 0
Accepted
time: 298ms
memory: 120084kb
input:
30 6 136665
output:
552360422
result:
ok single line: '552360422'
Test #5:
score: 0
Accepted
time: 256ms
memory: 120044kb
input:
178 6 51500
output:
788418998
result:
ok single line: '788418998'
Test #6:
score: 0
Accepted
time: 276ms
memory: 119944kb
input:
445 4 91471
output:
322733059
result:
ok single line: '322733059'
Test #7:
score: 0
Accepted
time: 305ms
memory: 120080kb
input:
23634 10 299334
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 357ms
memory: 119988kb
input:
242554 5 287650
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 214ms
memory: 119992kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 231ms
memory: 120084kb
input:
1 3 7
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 198ms
memory: 120020kb
input:
1 1 7
output:
7
result:
ok single line: '7'
Test #12:
score: 0
Accepted
time: 220ms
memory: 120068kb
input:
500000 500000 5000000
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 3385ms
memory: 119968kb
input:
250000 1 5000000
output:
578914111
result:
ok single line: '578914111'
Test #14:
score: 0
Accepted
time: 456ms
memory: 119996kb
input:
4096 6 449389
output:
129538870
result:
ok single line: '129538870'
Test #15:
score: 0
Accepted
time: 217ms
memory: 119976kb
input:
50 2 50
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 209ms
memory: 120084kb
input:
250000 65 5000000
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 3592ms
memory: 119984kb
input:
1 1 5000000
output:
5000000
result:
ok single line: '5000000'
Test #18:
score: 0
Accepted
time: 256ms
memory: 119968kb
input:
2 17 5000000
output:
7104108
result:
ok single line: '7104108'