QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719647 | #5586. Digits of Unity | nickbelov# | AC ✓ | 494ms | 304376kb | C++20 | 3.7kb | 2024-11-07 06:17:41 | 2024-11-07 06:17:42 |
Judging History
answer
#include <vector>
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
ostream_iterator<T> oit(const string &s = " "){ return ostream_iterator<T>(cout,s.c_str()); }
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
#define A(a) begin(a),end(a)
inline auto len = ranges::ssize;
struct chash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
typedef vector<ll> vll;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
const ll L = 23;
constexpr ll NN = 1<<23, M = 998244353;
ll f1[NN], f2[NN];
ll inv(ll a, ll b=M) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } // inv a mod b
ll choose(ll n, ll k) {
if(k>n) return 0LL;
return f1[n] * f2[k] % M * f2[n - k] % M; } // n choose k
void run()
{
auto flip = [](ll x){
return x ^ ((1LL<<23)-1);
};
ll n,k,m; cin >> n >> k >> m;
vll dp(m+1); { //too populate dp to sos on the inverse masks?
vll a(NN); for(ll i : rep1(0,m)) a[flip(i)]=1;
for(ll l = 0;l < L;l++) for(ll msk = 0; msk < NN; msk++)
if(msk & (1LL<<l)) a[msk] += a[msk^(1LL<<l)]; //mo need to mod here ?
ll sm = accumulate(A(a),0LL);
for(ll i : rep1(0,m)){
dp[i] = a[flip(i)];
}
}
//now lets actually compute the answer
vll dp2(NN);{
vll a(NN);
for(ll i : rep1(0,m)){
if(__builtin_popcount(i)<k) continue;
a[flip(i)] = choose(dp[i],n);
}
for(ll i : rep(NN)){
auto pc = __builtin_popcount(i);
if(pc%2) a[i] = (-1*a[i] + M) % M;
}
for(ll l = 0;l < L;l++) for(ll msk = 0; msk < NN; msk++)
if(msk & (1LL<<l)) a[msk] += a[msk^(1LL<<l)], a[msk]%=M;
for(ll i : rep(NN)){
auto pc = __builtin_popcount(i);
if(pc%2) a[i] = (-1*a[i] + M) % M;
}
// cout << a[NN-1] * f1[n] % M << endl;
for(ll i : rep1(m)){
if(__builtin_popcount(i)<k) continue;
dp2[i] = a[flip(i)];
}
}
ll ans = 0;
for(ll x : dp2) ans = (ans+x) % M;
ans = ans * f1[n] % M;
cout << ans << '\n';
}
int main()
{
//KING OF THE WORLD...... U.W.T.B
cin.tie(0);
ios_base::sync_with_stdio(false);
f1[0] = 1;
f2[0] = 1;
for (ll i = 1; i < NN; i++) {
f1[i] = f1[i - 1] * i % M;
}
f2[NN-1] = inv(f1[NN-1]);
for(ll i = NN-2;i>=1;i--){
f2[i] = (f2[i+1] * (i+1)) % M;
}
run();
}
详细
Test #1:
score: 100
Accepted
time: 451ms
memory: 265300kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 470ms
memory: 265308kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 440ms
memory: 266024kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: 0
Accepted
time: 448ms
memory: 266448kb
input:
30 6 136665
output:
552360422
result:
ok single line: '552360422'
Test #5:
score: 0
Accepted
time: 455ms
memory: 265752kb
input:
178 6 51500
output:
788418998
result:
ok single line: '788418998'
Test #6:
score: 0
Accepted
time: 418ms
memory: 265944kb
input:
445 4 91471
output:
322733059
result:
ok single line: '322733059'
Test #7:
score: 0
Accepted
time: 416ms
memory: 267584kb
input:
23634 10 299334
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 462ms
memory: 267480kb
input:
242554 5 287650
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 407ms
memory: 265220kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 476ms
memory: 265244kb
input:
1 3 7
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 450ms
memory: 265304kb
input:
1 1 7
output:
7
result:
ok single line: '7'
Test #12:
score: 0
Accepted
time: 420ms
memory: 304376kb
input:
500000 500000 5000000
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 469ms
memory: 304276kb
input:
250000 1 5000000
output:
578914111
result:
ok single line: '578914111'
Test #14:
score: 0
Accepted
time: 472ms
memory: 268828kb
input:
4096 6 449389
output:
129538870
result:
ok single line: '129538870'
Test #15:
score: 0
Accepted
time: 433ms
memory: 265248kb
input:
50 2 50
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 468ms
memory: 304276kb
input:
250000 65 5000000
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 485ms
memory: 304364kb
input:
1 1 5000000
output:
5000000
result:
ok single line: '5000000'
Test #18:
score: 0
Accepted
time: 494ms
memory: 304324kb
input:
2 17 5000000
output:
7104108
result:
ok single line: '7104108'