QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96505 | #5586. Digits of Unity | Nicolas125841 | WA | 266ms | 122396kb | C++14 | 2.3kb | 2023-04-14 00:52:18 | 2023-04-14 00:52:20 |
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;
}
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++;
vector<pair<int, ll>> vec;
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)
vec.emplace_back(i, perm(mx, n));
}
}
sort(vec.begin(), vec.end(), [](const auto &a, const auto &b){
return __builtin_popcount(a.first) < __builtin_popcount(b.first);
});
ll ans = 0;
for(auto p : vec){
if((__builtin_popcount(p.first) - __builtin_popcount(vec[0].first)) & 1)
ans -= p.second * (__builtin_popcount(p.first) - 1) % mod;
else
ans += p.second * (__builtin_popcount(p.first) - 1) % mod;
ans %= mod;
if(ans < 0)
ans += mod;
}
cout << ans << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 193ms
memory: 119980kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 229ms
memory: 119996kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 266ms
memory: 122396kb
input:
2 1 100000
output:
649006396
result:
wrong answer 1st lines differ - expected: '910073387', found: '649006396'