QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95780 | #5586. Digits of Unity | triplem5ds# | AC ✓ | 403ms | 81648kb | C++20 | 2.4kb | 2023-04-11 21:40:31 | 2023-04-11 21:40:39 |
Judging History
answer
///Enta etfsh5t nseet el rank
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
//#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ull = unsigned long long;
using uint = uint32_t;
using ii = pair<int, int>;
const int N = 5e6 + 20, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-9;
ll F[N], iF[N];
ll fast(ll b, ll e) {
int res = 1;
for (; e; e >>= 1, b = b * b % MOD)
if (e & 1)
res = res * b % MOD;
return res;
}
void init() {
F[0] = 1;
f(i, 1, N)F[i] = F[i - 1] * i % MOD;
iF[N - 1] = fast(F[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; --i)
iF[i] = iF[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
if (k > n || k < 0)
return 0;
return iF[k] * F[n] % MOD * iF[n - k] % MOD;
}
void doWork() {
int n, k, m;
cin >> n >> k >> m;
int ans = 0;
for (int mask = m; mask >= 0; --mask) {
int bits = popCnt(mask);
if (bits < k) continue;
int cnt = 0;
for (int x = 24, cur = bits; x >= cur; --x) {
if ((m + 1) >> x & 1) {
if (mask >> x & 1) cur -= 1;
else cnt += (1 << (x - cur));
} else {
if (mask >> x & 1)break;
}
}
int Choose = C(cnt, n);
for (int cur = bits; cur >= k; --cur) {
ans = (ans + MOD + ((bits & 1) == (cur & 1) ? +1 : -1) * C(bits, cur) * Choose % MOD) % MOD;
}
}
cout << ans * F[n] % MOD << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
init();
int t = 1;
// cin >> t;
while (t--)
doWork();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 42ms
memory: 81524kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 45ms
memory: 81536kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 46ms
memory: 81476kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: 0
Accepted
time: 47ms
memory: 81524kb
input:
30 6 136665
output:
552360422
result:
ok single line: '552360422'
Test #5:
score: 0
Accepted
time: 47ms
memory: 81532kb
input:
178 6 51500
output:
788418998
result:
ok single line: '788418998'
Test #6:
score: 0
Accepted
time: 39ms
memory: 81648kb
input:
445 4 91471
output:
322733059
result:
ok single line: '322733059'
Test #7:
score: 0
Accepted
time: 42ms
memory: 81548kb
input:
23634 10 299334
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 53ms
memory: 81428kb
input:
242554 5 287650
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 41ms
memory: 81640kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 37ms
memory: 81524kb
input:
1 3 7
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 45ms
memory: 81540kb
input:
1 1 7
output:
7
result:
ok single line: '7'
Test #12:
score: 0
Accepted
time: 46ms
memory: 81536kb
input:
500000 500000 5000000
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 388ms
memory: 81480kb
input:
250000 1 5000000
output:
578914111
result:
ok single line: '578914111'
Test #14:
score: 0
Accepted
time: 55ms
memory: 81428kb
input:
4096 6 449389
output:
129538870
result:
ok single line: '129538870'
Test #15:
score: 0
Accepted
time: 41ms
memory: 81424kb
input:
50 2 50
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 37ms
memory: 81468kb
input:
250000 65 5000000
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 403ms
memory: 81468kb
input:
1 1 5000000
output:
5000000
result:
ok single line: '5000000'
Test #18:
score: 0
Accepted
time: 35ms
memory: 81552kb
input:
2 17 5000000
output:
7104108
result:
ok single line: '7104108'