QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#259348 | #1254. Biggest Set Ever | chenxinyang2006 | WA | 478ms | 12300kb | C++14 | 6.9kb | 2023-11-20 20:38:49 | 2023-11-20 20:38:50 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define mpy(a,b) memcpy(a,b,sizeof(b))
#define dbg(...) cerr<<"#"<<__LINE__<<": "<<__VA_ARGS__<<endl
#define Fi(s) freopen(s,"r",stdin)
#define Fo(s) freopen(s,"w",stdout)
#define Fio(s) Fi(s".in"),Fo(s".out")
#define SZ(S) (int)S.size()
#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template<int P>
class mod_int{
using Z=mod_int;
private:
static int mo(int x){return x<0?x+P:x;}
public:
int x;
int val()const{return x;}
mod_int():x(0){}
template<class T>mod_int(const T&x_):x(x_>=0&&x_<P?static_cast<int>(x_):mo(static_cast<int>(x_%P))){}
bool operator==(const Z&rhs)const{return x==rhs.x;}
bool operator!=(const Z&rhs)const{return x!=rhs.x;}
Z operator-()const{return Z(x?P-x:0);}
Z pow(long long k)const{Z res=1,t=*this;while(k){if(k&1)res*=t;if(k>>=1)t*=t;}return res;}
Z&operator++(){x<P-1?++x:x=0;return *this;}
Z&operator--(){x?--x:x=P-1;return *this;}
Z operator++(int){Z ret=x;x<P-1?++x:x=0;return ret;}
Z operator--(int){Z ret=x;x?--x:x=P-1;return ret;}
Z inv()const{return pow(P-2);}
Z&operator+=(const Z&rhs){(x+=rhs.x)>=P&&(x-=P);return *this;}
Z&operator-=(const Z&rhs){(x-=rhs.x)<0&&(x+=P);return *this;}
Z&operator*=(const Z&rhs){x=1ULL*x*rhs.x%P;return *this;}
Z&operator/=(const Z&rhs){return *this*=rhs.inv();}
#define setO(T,o) friend T operator o(const Z&lhs,const Z&rhs){Z res=lhs;return res o##=rhs;}
setO(Z,+)setO(Z,-)setO(Z,*)setO(Z,/)
#undef setO
};
const int P = 998244353;
using Z = mod_int<P>;
ll qpow(ll x, ll k){
ll ret = 1;
while(k){
if(k & 1) (ret *= x) %= mod;
(x *= x) %= mod, k >>= 1;
}
return ret;
}
namespace Poly_space{
Z inv2 = (P + 1) / 2;
vector<int> rev;
vector<Z> gg = {0, 1};
Z rt = 3;
void setroot(Z x){rt = x;}
void dft(vector<Z> &a){
int n = a.size();
if((int)rev.size() != n){
int k = __builtin_ctz(n) - 1; rev.resize(n);
for(int i = 0; i < n; i++){rev[i] = rev[i >> 1] >> 1 | (i & 1 ? (1 << k) : 0);}
}
for(int i = 0; i < n; i++) if(i < rev[i]) swap(a[i], a[rev[i]]);
if((int)gg.size() < n){
int k = __builtin_ctz(gg.size()); gg.resize(n);
while((1 << k) < n){
Z e = rt.pow((P - 1) >> (k + 1));
for(int i = (1 << (k - 1)); i < (1 << k); i++) gg[i << 1] = gg[i], gg[(i << 1) | 1] = gg[i] * e;
k++;
}
}
for(int mid = 1; mid < n; mid <<= 1) for(int i = 0; i < n; i += (mid << 1)) for(int j = 0; j < mid; j++){
Z x = a[i + j], y = a[i + j + mid] * gg[mid + j];
a[i + j] = x + y, a[i + j + mid] = x - y;
}
}
void idft(vector<Z> &a){
int n = a.size(); reverse(a.begin() + 1, a.end()), dft(a);
Z inv = Z(1 - P) / Z(n); for(int i = 0; i < n; i++) a[i] *= inv;
}
struct Poly{
vector<Z> a;
Poly(){} Poly(const vector<Z> &x): a(x){} Poly(const initializer_list<Z> &x): a(x){}
int size()const{return a.size();} void resize(int x){a.resize(x);}
Z operator [](int ind)const{if(ind < 0 || ind >= size()) return 0; return a[ind];}
Z&operator [](int ind){return a[ind];}
Poly modxk(int k)const{k = min(k, size()); return Poly(vector<Z>(a.begin(), a.begin() + k));}
Poly mulxk(int k)const{vector<Z> b = a; b.insert(b.begin(), k, 0); return b;}
Poly divxk(int k)const{if(size() <= k) return Poly(); return Poly(vector<Z>(a.begin() + k, a.end()));}
friend Poly operator + (const Poly &a, const Poly &b){
vector<Z> ret(max(a.size(), b.size()));
for(int i = 0; i < ret.size(); i++) ret[i] = a[i] + b[i];
return Poly(ret);
}
friend Poly operator - (const Poly &a, const Poly &b){
vector<Z> ret(max(a.size(), b.size()));
for(int i = 0; i < ret.size(); i++) ret[i] = a[i] - b[i];
return Poly(ret);
}
friend Poly operator * (const Poly &a, const Z &b){
vector<Z> ret(a.size());
for(int i = 0; i < ret.size(); i++) ret[i] = a[i] * b;
return Poly(ret);
}
friend Poly operator * (Poly a, Poly b){
if(a.size() == 0 || b.size() == 0) return Poly();
int sz = 1, n = a.size() + b.size() - 1;
while(sz < n) sz <<= 1;
a.resize(sz), b.resize(sz), dft(a.a), dft(b.a);
for(int i = 0; i < sz; i++) a.a[i] = a[i] * b[i];
idft(a.a), a.resize(n); return a;
}
Poly inv(int deg)const{
if(deg == 1) return Poly({a[0].pow(P - 2)});
Poly res = inv((deg + 1) >> 1), tmp = *this;
int sz = 1; while(sz < (deg << 1)) sz <<= 1;
tmp = tmp.modxk(deg), tmp.resize(sz), res.resize(sz);
dft(tmp.a), dft(res.a);
for(int i = 0; i < sz; i++) res[i] = 2 * res[i] - res[i] * res[i] * tmp[i];
idft(res.a), res.resize(deg);
return res;
}
Poly derivative()const{
if(size() == 1) return Poly();
Poly ret(vector<Z>(size() - 1));
for(int i = 1; i < size(); i++) ret.a[i - 1] = a[i] * i;
return ret;
}
Poly integrate()const{
Poly ret(vector<Z>(size() + 1));
for(int i = 1; i < ret.size(); i++) ret.a[i] = a[i - 1] * Z(i).inv();
return ret;
}
Poly ln(int deg){
Poly res = derivative(), tmp = inv(deg);
res = (res * tmp).integrate(), res.resize(deg);
return res;
}
Poly exp(int deg){
Poly ret(vector<Z>(1)); ret[0] = 1; int i = 1;
while(i < deg) i <<= 1, ret = (ret * (Poly({1}) - ret.ln(i) + modxk(i))).modxk(i);
return ret.modxk(deg);
}
};
}
using namespace Poly_space;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
Z fact[1000005],ifac[1000005];
Z C(int N,int M){
if(N < M || M < 0) return 0;
return fact[N] * ifac[M] * ifac[N - M];
}
void init(int L){
fact[0] = 1;
rep(i,1,L) fact[i] = fact[i - 1] * i;
ifac[L] = 1 / fact[L];
per(i,L - 1,0) ifac[i] = ifac[i + 1] * (i + 1);
}
int n,r,L;
char s[100005];
void mo(Poly &f){
rep(i,n,2 * n - 2) f.a[i - n] += f.a[i];
f = f.modxk(n);
}
Z f[10005],g[10005];
Poly cur,res;
void calc(int K){
rep(i,0,n - 1){
cur.a.eb(g[i]);
res.a.eb((int)(i == 0));
}
rep(p,0,29){
if((K >> p) & 1){
res = res * cur;
mo(res);
}
cur = cur * cur;
mo(cur);
}
}
int main(){
scanf("%d%d",&n,&r);
scanf("%s",s + 1);
L = strlen(s + 1);
g[0] = 1;
rep(i,0,n - 1){
rep(j,0,n - 1) f[(i + j) % n] += g[j];
rep(j,0,n - 1){
g[j] += f[j];
f[j] = 0;
}
}
ll S = 0;
rep(i,1,L) S = (S * 10 + s[i] - '0') % (1ll * (mod - 1) * n);
// rep(i,0,n - 1) printf("%d ",g[i].val());
// printf("\n");
calc(S / n);
rep(i,0,n - 1) g[i] = res.a[i];
rep(i,0,S % n - 1){
rep(j,0,n - 1) f[(i + j) % n] += g[j];
rep(j,0,n - 1){
g[j] += f[j];
f[j] = 0;
}
}
printf("%d\n",g[r].val());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11968kb
input:
3 2 5
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11788kb
input:
1 0 20
output:
1048576
result:
ok single line: '1048576'
Test #3:
score: 0
Accepted
time: 2ms
memory: 11612kb
input:
10 8 97441781169999
output:
39483594
result:
ok single line: '39483594'
Test #4:
score: 0
Accepted
time: 0ms
memory: 11704kb
input:
10 0 73529553919999
output:
913188246
result:
ok single line: '913188246'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11680kb
input:
10 5 7216893652
output:
803006513
result:
ok single line: '803006513'
Test #6:
score: 0
Accepted
time: 2ms
memory: 11964kb
input:
51 4 490466735660935366104362911237439817660296497884511278059120667639249811034386376211440059814876153833104198879999
output:
754741857
result:
ok single line: '754741857'
Test #7:
score: 0
Accepted
time: 0ms
memory: 11676kb
input:
45 0 6216871967465786523158710331777577058507955388049665933617608862925909208090781993189722633093256714163855609550090284484136100755698161980229368887021285893611742334609577808667250730098679567168835635687562524497440298178123243152474212724715349775392879081815671155873083166544656572426801376...
output:
247716490
result:
ok single line: '247716490'
Test #8:
score: 0
Accepted
time: 2ms
memory: 11980kb
input:
123 95 82762777129999
output:
104574851
result:
ok single line: '104574851'
Test #9:
score: 0
Accepted
time: 2ms
memory: 11708kb
input:
100 8 31437474627210849758566270683758273881261075882083602376365854183768172131884521374556483688326470349999
output:
204425046
result:
ok single line: '204425046'
Test #10:
score: 0
Accepted
time: 2ms
memory: 11704kb
input:
101 65 129135732687243444162224693341284265097302999818949156642879266983062901971745283891629743024085567839999
output:
902554661
result:
ok single line: '902554661'
Test #11:
score: 0
Accepted
time: 0ms
memory: 11772kb
input:
102 0 3488151969475412325389878205822308160017247852281650623347454005909349359794006198664575307015721114499999
output:
162486241
result:
ok single line: '162486241'
Test #12:
score: 0
Accepted
time: 8ms
memory: 11808kb
input:
1012 291 7646813626
output:
980146392
result:
ok single line: '980146392'
Test #13:
score: 0
Accepted
time: 2ms
memory: 11968kb
input:
10 1 8252321334895940615769970904772140913784950414733677250236907211278760730743749190165425246198980003063223759998857676592610546612494049860039116369420896260329913339201912705127782100719073680933781912596330763621573961781964610789874205137283507240907978239171437180129623254976853141357534721...
output:
652741132
result:
ok single line: '652741132'
Test #14:
score: 0
Accepted
time: 467ms
memory: 11912kb
input:
10000 7418 3245239614838766441165109131458206859599048822364196500920217765340625035454604743711500986644932444050563968810069079688108908878846571710567968402401812796927116289077099295526340820005662199516680283500266534222567954309211983031474586099314642398538154929871106845369013158161741156285...
output:
698356153
result:
ok single line: '698356153'
Test #15:
score: 0
Accepted
time: 277ms
memory: 12008kb
input:
9999 779 358336376636226042717427621455961243958393374012413730691317569180699582766828947496902145881339115917085532012414592514320100982450700615324388139090946345231102734023340224881463299658303159811283914016535239877151817544726113079790779414960958512664223829472539894897355539363031791406089...
output:
837883243
result:
ok single line: '837883243'
Test #16:
score: 0
Accepted
time: 464ms
memory: 12008kb
input:
10000 0 5959081123960981456052979042226085365217802503520521998482870583390422819313350263042136451463933153462392827184151729621677652847629006369849703956071611814775739516186470151700231702587051465357283648453972097435393937208562095551505345722276019216674741689533178156201652677931133018670075...
output:
924699691
result:
ok single line: '924699691'
Test #17:
score: 0
Accepted
time: 404ms
memory: 12012kb
input:
10000 9535 4529914918413777622528043117043450937202591529390096894597801955131392043838551780190373994052685563959267673748578051484778843491690348530040553041327206108222053240121197654468570203072462947279505179444683716795754611201162765280673498257918169149948361212426058346508829709396950512100...
output:
984036477
result:
ok single line: '984036477'
Test #18:
score: 0
Accepted
time: 397ms
memory: 12096kb
input:
9240 4639 27361723410151521150732754757747824591816341408004277395827380018571695767504374102641417978743103148415278527868597085535196798439563729486914117045504466181228391680543038904853912910914033179148538533773830859471039264891096812737067663728830538925263207278489348217296058385024096176645...
output:
918206285
result:
ok single line: '918206285'
Test #19:
score: 0
Accepted
time: 284ms
memory: 11992kb
input:
8640 0 36542487284167251663740647042989590271004990959161565599035618320359555884164889579638216196822119364835481192513876617252278990351166475479529866772377957875189299536492571051813538976297743058308068985113568320877021600430398281676260145773030952556440352937340499556103082922663344786146031...
output:
183559339
result:
ok single line: '183559339'
Test #20:
score: 0
Accepted
time: 230ms
memory: 11988kb
input:
8400 300 288271854704449002303660023988228953095431900267967796390634942331317772470120001601892932430552455756800781384921666042619127984502628855577098517482540354318793004328371417736520135839821219973136389836602550635594752488595369449820630558647394225301132623150116886896899160930010237898661...
output:
236192822
result:
ok single line: '236192822'
Test #21:
score: 0
Accepted
time: 414ms
memory: 12096kb
input:
9900 7932 60696943972373113723790595629126483514286522739943462090310067978198194825062752363577899690215576140733032790987877947244269329280647842553127506268616051081441746603578834885861401552062986268589398127724619814495854782291653679848340686262859158150894989658137076297136845970234357040248...
output:
957197274
result:
ok single line: '957197274'
Test #22:
score: 0
Accepted
time: 195ms
memory: 12152kb
input:
8064 0 47334321587030653743112677374440705129805126456129176300634909485205142778452960069919888488272962888344558362309553430584472473664877747506095230385831376281275441466113307422446138481496975295148631099507964104577181484367166622611546731949305572711810831571898086598100505274361166695152297...
output:
669865153
result:
ok single line: '669865153'
Test #23:
score: 0
Accepted
time: 184ms
memory: 12212kb
input:
7560 4251 33923778033803241908219943724011782970171842843279830346925914273149746589031596306410354155061775627084155077246765927736846008968413480151788681683200760666695266835650540805104008248152259180695495822884752048464024168111056913040542477162151971025210582160878305329922703362973968810986...
output:
416930414
result:
ok single line: '416930414'
Test #24:
score: 0
Accepted
time: 2ms
memory: 11772kb
input:
1 0 1
output:
2
result:
ok single line: '2'
Test #25:
score: 0
Accepted
time: 2ms
memory: 11760kb
input:
20 0 1
output:
2
result:
ok single line: '2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 11772kb
input:
20 13 1
output:
0
result:
ok single line: '0'
Test #27:
score: 0
Accepted
time: 478ms
memory: 12012kb
input:
10000 4469 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
290641673
result:
ok single line: '290641673'
Test #28:
score: 0
Accepted
time: 186ms
memory: 11928kb
input:
7560 4041 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
74525042
result:
ok single line: '74525042'
Test #29:
score: 0
Accepted
time: 431ms
memory: 12300kb
input:
9973 5944 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
881015534
result:
ok single line: '881015534'
Test #30:
score: 0
Accepted
time: 253ms
memory: 12300kb
input:
9240 105 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
971384312
result:
ok single line: '971384312'
Test #31:
score: 0
Accepted
time: 272ms
memory: 11836kb
input:
9240 407 3576
output:
801993513
result:
ok single line: '801993513'
Test #32:
score: -100
Wrong Answer
time: 228ms
memory: 11976kb
input:
9240 551 204209679712117827730880226353510653024223856012233043639816521107053027427255530900909664190550923070609753205194078932813278453978969048551211039657884854091997550079122709572652601873661760656527148885540570009859983720628938737170862051434146563351143193685385454224852792784922646291244...
output:
61877843
result:
wrong answer 1st lines differ - expected: '119770088', found: '61877843'