QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95565 | #5586. Digits of Unity | Nicolas125841 | WA | 267ms | 120176kb | C++14 | 2.0kb | 2023-04-10 15:07:21 | 2023-04-10 15:07:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
vector<ll> fac(5000001, 0), ifac(5000001, 0), inv(5000001, 0);
ll perm(int n, int k){
return fac[n] * 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;
ll ans = 0;
int ml = 0;
while((1<<ml) <= m)
ml++;
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];
assert(mx <= 5000000);
if(mx >= n){
if((__builtin_popcount(i) - k) & 1)
ans -= perm(mx, n);
else
ans += perm(mx, n);
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: 193ms
memory: 120176kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 213ms
memory: 120176kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 249ms
memory: 120176kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: -100
Wrong Answer
time: 267ms
memory: 120124kb
input:
30 6 136665
output:
274209335
result:
wrong answer 1st lines differ - expected: '552360422', found: '274209335'