QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#5764 | #1254. Biggest Set Ever | Qingyu | 100 ✓ | 642ms | 6132kb | C++17 | 2.1kb | 2021-01-15 20:47:11 | 2021-12-19 06:53:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> poly;
const int Mod=998244353;
const int G=3;
int n,rem; poly f,g;
int rev[810000]; char t[110000];
inline ll add(ll x,ll y){ return x+y>=Mod?x+y-Mod:x+y;}
inline ll dec(ll x,ll y){ return x-y<0?x-y+Mod:x-y;}
ll qpow(ll x,ll a){
ll res=1;
while (a){
if (a&1) res=res*x%Mod;
x=x*x%Mod; a>>=1;
}
return res;
}
ll getinv(ll x){ return qpow(x,Mod-2);}
void NTT(poly &a,int len,int inv){
a.resize(len);
for (int i=0;i<len;i++)
if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int mid=1;mid<len;mid<<=1){
ll tmp=qpow(G,(Mod-1)/(mid<<1));
if (inv==-1) tmp=getinv(tmp);
for (int i=0;i<len;i+=(mid<<1)){
ll omega=1;
for (int j=0;j<mid;j++,omega=omega*tmp%Mod){
ll x=a[i+j],y=omega*a[i+j+mid]%Mod;
a[i+j]=add(x,y); a[i+j+mid]=dec(x,y);
}
}
}
if (inv==-1){
ll tmp=getinv(len);
for (int i=0;i<len;i++) a[i]=a[i]*tmp%Mod;
}
}
void polymul(int n,poly &f,poly g){//deg(f)<n,deg(g)<n,f*g mod (x^n-1)
int len=1,bit=0;
while (len<(n<<1)) len<<=1,bit++;
for (int i=0;i<len;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
NTT(f,len,1); NTT(g,len,1);
for (int i=0;i<len;i++) f[i]=f[i]*g[i]%Mod;
NTT(f,len,-1);
for (int i=n;i<len;i++) f[i%n]=add(f[i%n],f[i]);
f.resize(n);
}
void qpow(poly &f,ll c){
poly g; g.resize(n); g[0]=1;
while (c){
if (c&1) polymul(n,g,f);
polymul(n,f,f); c>>=1;
}
f=g;
}
int main(){
scanf("%d%d",&n,&rem);
f.resize(n); g.resize(n);
f[0]=1;
for (int i=0;i<n;i++){//(1+x^0)(1+x^1)...(1+x^i)
for (int j=0;j<n;j++) g[j]=f[j];
for (int j=0;j<n;j++) g[(j+i)%n]=add(g[(j+i)%n],f[j]);
for (int j=0;j<n;j++) f[j]=g[j];
}
scanf("%s",t+1); int len=(int)strlen(t+1);
ll c=0,d,x=0;
for (int i=1;i<=len;i++){
d=(x*10+(t[i]-'0'))/n;
c=(c*10+d)%(Mod-1);
x=(x*10+(t[i]-'0'))%n;
}
qpow(f,c);
for (int i=0;i<x;i++){
for (int j=0;j<n;j++) g[j]=f[j];
for (int j=0;j<n;j++) g[(j+i)%n]=add(g[(j+i)%n],f[j]);
for (int j=0;j<n;j++) f[j]=g[j];
}
printf("%lld\n",f[rem]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 3
Accepted
time: 2ms
memory: 3604kb
input:
98 7 10
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 3
Accepted
time: 0ms
memory: 3596kb
input:
89 85 34
output:
193043360
result:
ok 1 number(s): "193043360"
Test #3:
score: 3
Accepted
time: 2ms
memory: 3592kb
input:
94 0 32
output:
45614668
result:
ok 1 number(s): "45614668"
Test #4:
score: 3
Accepted
time: 0ms
memory: 3668kb
input:
60 53 48
output:
499396021
result:
ok 1 number(s): "499396021"
Test #5:
score: 3
Accepted
time: 0ms
memory: 3648kb
input:
35 32 52
output:
577965884
result:
ok 1 number(s): "577965884"
Test #6:
score: 3
Accepted
time: 2ms
memory: 5652kb
input:
24 23 89
output:
406940195
result:
ok 1 number(s): "406940195"
Test #7:
score: 3
Accepted
time: 2ms
memory: 3624kb
input:
27 0 71
output:
574148512
result:
ok 1 number(s): "574148512"
Test #8:
score: 3
Accepted
time: 1ms
memory: 3620kb
input:
42 23 13
output:
156
result:
ok 1 number(s): "156"
Test #9:
score: 3
Accepted
time: 2ms
memory: 3728kb
input:
47 3 67
output:
413518112
result:
ok 1 number(s): "413518112"
Test #10:
score: 3
Accepted
time: 2ms
memory: 3608kb
input:
68 42 16
output:
920
result:
ok 1 number(s): "920"
Test #11:
score: 3
Accepted
time: 642ms
memory: 4260kb
input:
9797 5544 21964788
output:
708551585
result:
ok 1 number(s): "708551585"
Test #12:
score: 3
Accepted
time: 301ms
memory: 4060kb
input:
8018 3462 22926104
output:
635919360
result:
ok 1 number(s): "635919360"
Test #13:
score: 3
Accepted
time: 65ms
memory: 3848kb
input:
3920 2702 79294111
output:
530801031
result:
ok 1 number(s): "530801031"
Test #14:
score: 3
Accepted
time: 15ms
memory: 3768kb
input:
1083 299 62722485
output:
805048331
result:
ok 1 number(s): "805048331"
Test #15:
score: 3
Accepted
time: 398ms
memory: 4284kb
input:
9604 3640 72953401
output:
944898017
result:
ok 1 number(s): "944898017"
Test #16:
score: 3
Accepted
time: 487ms
memory: 4208kb
input:
9325 44 48830931
output:
909574979
result:
ok 1 number(s): "909574979"
Test #17:
score: 3
Accepted
time: 87ms
memory: 3768kb
input:
3470 1650 81579097
output:
688877527
result:
ok 1 number(s): "688877527"
Test #18:
score: 3
Accepted
time: 430ms
memory: 4024kb
input:
8121 2022 52867347
output:
539738689
result:
ok 1 number(s): "539738689"
Test #19:
score: 3
Accepted
time: 211ms
memory: 3968kb
input:
6781 6183 60467731
output:
866136177
result:
ok 1 number(s): "866136177"
Test #20:
score: 3
Accepted
time: 232ms
memory: 3968kb
input:
6052 1331 34501056
output:
500969300
result:
ok 1 number(s): "500969300"
Test #21:
score: 3
Accepted
time: 9ms
memory: 3816kb
input:
450 42 3632149156083569276305586082890120302288781244030534902855531202282530436185113321757322846054758622386825391367932424584575093821285406088608189231399368209651890122772664931715223427925404525437113957338543604502103703399695074697955059147295926388766740751195770157045156591403999082540287776689881950211097902490901464866468509859276822030003513131435371963466541380381072686687821796218347724677226695749831337180015206153791434929786285406893362944025380589151829843445664056442089106628...
output:
913253853
result:
ok 1 number(s): "913253853"
Test #22:
score: 3
Accepted
time: 166ms
memory: 3944kb
input:
4111 1598 9811442912654533224843790895776015859846013754041389285832093328745475189177460466175149972152730857561530828255825206616917870331528017841936293882569469799976335277930209099649827849940707852949706197538465005245749237585308318901774486821771519202314649951685090934945276891716863343835399032302646184530957701899633609916708292363950186644268340814228262912159383899640578797299668105443532724215636019626238288211834510394471836590340943583704365083581174382343565437816940532745684015...
output:
841123437
result:
ok 1 number(s): "841123437"
Test #23:
score: 3
Accepted
time: 245ms
memory: 4004kb
input:
6319 5686 7122152710187308937273070669678217103775029662105666545551061056505780821137996148312638551567262160158810095461893924001344073754648188516699361621959262816951455412960932943119069488222730785402519441595530187744423774053103931226021525864374718405675053949656491060169907003718809572505137145469190673340636058374243763897662865474629242711125436354724364225052180512574759514230541458549254494629640819325888949051200668016506191659700541069992856142183621923054225668608582575573050234...
output:
37269163
result:
ok 1 number(s): "37269163"
Test #24:
score: 3
Accepted
time: 278ms
memory: 4036kb
input:
6352 684 11132165160918647603686548550599340864905872969628799946056730891971279195169950708313045412859782736614572831962774623100912884252616042357497813781322560982414483296160919376251492038610541436304647149187345190817796887236765464009865907050092318830279380210209991818639547750380862131590348744480504882045625634225835205854697760146932310877482387221932764667928522139626479344439991559950081565984834755735493281954079593459743723211120743929020927221799566957077054242408945706635643807...
output:
573762493
result:
ok 1 number(s): "573762493"
Test #25:
score: 3
Accepted
time: 27ms
memory: 3780kb
input:
1398 589 55734367368917923155937615274326230719141613350146593196898973174101818016521384879462597360846913119845259004311848162905544652092888997493704696138038132542726781635972516101265990292446710701074182504292467515537525022597222710018648918584013725749100938817474022896133988212007462461406523714001183554309731037085749358596714475965596290584298586838667954613409415679951199982736455388916851439760710626942643373582099241012193281021910751287973157074652659699966943558633103904873797882...
output:
831411345
result:
ok 1 number(s): "831411345"
Test #26:
score: 3
Accepted
time: 85ms
memory: 5844kb
input:
3397 1748 7469015623560442118622839275239467348238201040161360476164907847151336964208497475057679670963465132867247603515968869070505452961122215224748479100419401557862086516804678685874070965753316405656634008350033767432845520784025918492211754543214944734807067341664109597735830237234046336948770161787829507718280906540366464851486111976936104255777500644368171076558935887749762061155465525450931909003549297401790415092262593498807202915977818734057666867711787898534067690986447697838204677...
output:
141903325
result:
ok 1 number(s): "141903325"
Test #27:
score: 3
Accepted
time: 466ms
memory: 4340kb
input:
8255 1184 6067452068610277941107109753409860901831237252012565850234617926817308811968663744502446950369555174181766739386218650705164672620207858970723996837381031979125040295290627395419611613544377770808927018701340089139899951014516703399824068605626442297213478480657073881312419928120308553270720683044197055198330038133671188383243644407625240134167113468577158517331600995616879980578672160083498629098775978253440417549679732678265501266613004255713716126338978304013385057119886257965923110...
output:
246166531
result:
ok 1 number(s): "246166531"
Test #28:
score: 3
Accepted
time: 273ms
memory: 4060kb
input:
5798 3543 2344926737240319573194201419121992852190575255529435459790192701426379191405170677402163689082128777606479487948503965846623505152176261193639390536856381307315140208274999076240230766510223868389970644998165684677637468416879347115767206712427586835226227110496661822646240891124361454045938240330442001339428969355387200255726110212051134388821422901658471594198863101491200769158596888934973797472892612969723562755460914582701985065930561503440793701936761412419560329844144087781436746...
output:
221905573
result:
ok 1 number(s): "221905573"
Test #29:
score: 3
Accepted
time: 451ms
memory: 6132kb
input:
7851 5072 6898129665589902970456399747209112790895510441329114337654095556800854131124514829957739064089101435727835193947355055621169450384045368962820241274480986121558744408192392950456355963420857115425756177519742923459694767075094966719905089194564529775908585957081185709041686885498598598505012468956116202779520689316826190792973952106955867857513229955939591878116341027543244877062878457640560662751297589672715652844558477840259582456272683211715594622123168954894587072131441192124295169...
output:
762627472
result:
ok 1 number(s): "762627472"
Test #30:
score: 3
Accepted
time: 95ms
memory: 3860kb
input:
3740 1099 3621328258668623621275784985352059131875910120763597507280239233679744091539929912474262449388544012431004538112385432772092658124202031763070521456411035196848233858228770928985219611825229721807953130505625042681894581471280297792116314700575454802144366902700790326576640094498125228775912278708312116734886593187044464821570470881119831247775824048169133523805648729233448114356963276802378752837896821251489152062915237077138810499319305777738261186980599086514157403817349225653395126...
output:
498110720
result:
ok 1 number(s): "498110720"