QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102327 | #5586. Digits of Unity | joesmitty | AC ✓ | 1002ms | 89468kb | C++20 | 5.6kb | 2023-05-03 02:55:44 | 2023-05-03 02:55:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX;
long double PI = 4*atan(1);
long double eps = 1e-12;
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint():v(0) {}
mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD; }
bool operator==(const mint& o) const {
return v == o.v; }
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b); }
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v; }
// friend void re(mint& a) { ll x; re(x); a = mint(x); }
// friend str ts(mint a) { return ts(a.v); }
mint& operator+=(const mint& o) {
if ((v += o.v) >= MOD) v -= MOD;
return *this; }
mint& operator-=(const mint& o) {
if ((v -= o.v) < 0) v += MOD;
return *this; }
mint& operator*=(const mint& o) {
v = int((ll)v*o.v%MOD); return *this; }
mint& operator/=(const mint& o) { return (*this) *= inv(o); }
friend mint mpow(mint a, ll p) {
mint ans = 1; //assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans; }
friend mint inv(const mint& a) { //assert(a.v != 0);
return mpow(a,MOD-2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
using mi = mint<MOD,5>; // 5 is primitive root for both common mods
int n,m,k;
vvi cnt(24);
mi fact[6000010] = {};
mi invf[6000010] = {};
mi choose(int a, int b) {
if(b < 0 || b > a) return 0;
return fact[a] * invf[b] * invf[a-b];
}
mi calc(int kv) {
mi tot = 0;
for(auto x : cnt[kv]) {
if(x > m) continue;
// cout << "x: " << x << endl;
vi other;
FOR(i,0,24) {
if(((1 << i) & x) == 0) other.pb(1 << i);
}
int rem = m - x;
int numg = 0;
// cout << rem << endl;
RFOR(i,other.size(),0) {
if(rem >= other[i]) {
// cout << "i: " << i << endl;
numg += (1 << i);
rem -= other[i];
// cout << rem << endl;
}
}
numg++;
// cout << "numg: " << numg << endl;
tot += choose(numg, n);
}
return tot * fact[n];
}
int main() {
//auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);cin.tie(0);
// ofstream cout("disrupt.out");
// ifstream cin("disrupt.in");
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> k >> m;
fact[0] = 1;
FOR(i,1,6000010) {
fact[i] = fact[i-1] * i;
}
invf[6000009] = inv(fact[6000009]);
RFOR(i,6000009, 0) {
invf[i] = (i+1) * invf[i+1];
}
FOR(i,0,(1<<23)) {
int c = 0;
FOR(j,0,23) {
if((1 << j) & i) c++;
}
cnt[c].pb(i);
}
vector<mi> coefs = {};
mi ans = 0;
FOR(kv,k,24) {
mi tot = calc(kv);
// cout << kv << " " << tot.v << endl;
mi curr = 0;
FOR(i,0,coefs.size()) {
curr += coefs[i] * choose(kv, k+i);
}
mi newcoef = 1 - curr;
coefs.pb(newcoef);
ans += newcoef * tot;
}
// for(auto x : coefs) {
// cout << x.v << " ";
// }
// cout << endl;
cout << ans.v << endl;
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 95ms
memory: 89444kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 115ms
memory: 89448kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 153ms
memory: 89320kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: 0
Accepted
time: 139ms
memory: 89324kb
input:
30 6 136665
output:
552360422
result:
ok single line: '552360422'
Test #5:
score: 0
Accepted
time: 129ms
memory: 89388kb
input:
178 6 51500
output:
788418998
result:
ok single line: '788418998'
Test #6:
score: 0
Accepted
time: 117ms
memory: 89452kb
input:
445 4 91471
output:
322733059
result:
ok single line: '322733059'
Test #7:
score: 0
Accepted
time: 157ms
memory: 89448kb
input:
23634 10 299334
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 165ms
memory: 89448kb
input:
242554 5 287650
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 120ms
memory: 89352kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 101ms
memory: 89428kb
input:
1 3 7
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 112ms
memory: 89384kb
input:
1 1 7
output:
7
result:
ok single line: '7'
Test #12:
score: 0
Accepted
time: 106ms
memory: 89404kb
input:
500000 500000 5000000
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 979ms
memory: 89356kb
input:
250000 1 5000000
output:
578914111
result:
ok single line: '578914111'
Test #14:
score: 0
Accepted
time: 180ms
memory: 89468kb
input:
4096 6 449389
output:
129538870
result:
ok single line: '129538870'
Test #15:
score: 0
Accepted
time: 122ms
memory: 89396kb
input:
50 2 50
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 117ms
memory: 89404kb
input:
250000 65 5000000
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 1002ms
memory: 89448kb
input:
1 1 5000000
output:
5000000
result:
ok single line: '5000000'
Test #18:
score: 0
Accepted
time: 104ms
memory: 89368kb
input:
2 17 5000000
output:
7104108
result:
ok single line: '7104108'