QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95831 | #5586. Digits of Unity | Username# | WA | 57ms | 42544kb | C++14 | 1.9kb | 2023-04-11 23:19:12 | 2023-04-11 23:19:13 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
typedef long long ll;
typedef long double ld;
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 5e6 + 5, M = 998244353;
int m, id, cur;
int fact[N], inv[N], dp[23][2], vis[23][2];
int add(int a, int b) {
b = (b % M + M) % M;
return (a + b) % M;
}
int mul(int a, int b) {
return 1LL * a * b % M;
}
int modPow(int b, int p) {
if (p == 0)
return 1;
int x = modPow(b, p / 2);
return p % 2 == 0 ? mul(x, x) : mul(b, mul(x, x));
}
int modInvFer(int n) {
return modPow(n, M - 2);
}
void pre() {
fact[0] = 1;
for (int i = 1; i < N; i++)
fact[i] = mul(fact[i - 1], i);
inv[N - 1] = modInvFer(fact[N - 1]);
for (int i = N - 2; i >= 0; i--)
inv[i] = mul(inv[i + 1], i + 1);
}
int ncr(int n, int r) {
return mul(fact[n], mul(inv[r], inv[n - r]));
}
int solve(int bit, bool eq) {
if (bit < 0)
return 1;
int &ret = dp[bit][eq];
if (vis[bit][eq] == id)
return ret;
vis[bit][eq] = id;
ret = 0;
if (!(cur >> bit & 1))
ret = solve(bit - 1, eq & !(m >> bit & 1));
if (!eq || m >> bit & 1)
ret += solve(bit - 1, eq);
return ret;
}
void testCase() {
pre();
int n, k;
cin >> n >> k >> m;
int sol = 0;
for (int msk = 1; msk <= m; msk++) {
cur = msk, id++;
int pc = __builtin_popcount(msk);
if (pc < k || solve(22, 1) < n)
continue;
if ((pc - k) & 1)
sol = add(sol, -ncr(solve(22, 1), n));
else
sol = add(sol, ncr(solve(22, 1), n));
}
cout << mul(sol, fact[n]);
}
signed main() {
Beevo
int t = 1;
// cin >> t;
while (t--)
testCase();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 47ms
memory: 42460kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 37ms
memory: 42512kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 55ms
memory: 42528kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: -100
Wrong Answer
time: 57ms
memory: 42544kb
input:
30 6 136665
output:
274209335
result:
wrong answer 1st lines differ - expected: '552360422', found: '274209335'