QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#6281 | #547. BM 算法 | Qingyu | 0 | 317ms | 283912kb | C++11 | 4.7kb | 2021-03-02 20:16:37 | 2021-12-19 08:27:50 |
Judging History
This is the latest submission verdict.
- [2024-12-28 21:37:58]
- hack成功,自动添加数据
- (/hack/1317)
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2021-03-02 20:16:37]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=3e5+51,MOD=998244353,G=3,INVG=332748118;
ll exponent,fd,cnt=1,limit=-1,rres,ptr;
ll rev[MAXN],f[MAXN],g[MAXN],tmp[MAXN],tmp2[MAXN],tmp3[MAXN],tbm[MAXN];
ll res[MAXN],base[MAXN],fail[MAXN];
li delta[MAXN];
inline ll read()
{
register ll num=0,neg=1;
register char ch=getchar();
while(!isdigit(ch)&&ch!='-')
{
ch=getchar();
}
if(ch=='-')
{
neg=-1;
ch=getchar();
}
while(isdigit(ch))
{
num=(num<<3)+(num<<1)+(ch-'0');
ch=getchar();
}
return num*neg;
}
inline ll qpow(ll base,ll exponent)
{
li res=1;
while(exponent)
{
if(exponent&1)
{
res=1ll*res*base%MOD;
}
base=1ll*base*base%MOD,exponent>>=1;
}
return res;
}
inline void NTT(ll *cp,ll cnt,ll inv)
{
ll cur=0,res=0,omg=0;
for(register int i=0;i<cnt;i++)
{
if(i<rev[i])
{
swap(cp[i],cp[rev[i]]);
}
}
for(register int i=2;i<=cnt;i<<=1)
{
cur=i>>1,res=qpow(inv==1?G:INVG,(MOD-1)/i);
for(register ll *p=cp;p!=cp+cnt;p+=i)
{
omg=1;
for(register int j=0;j<cur;j++)
{
ll t=1ll*omg*p[j+cur]%MOD,t2=p[j];
p[j+cur]=(t2-t+MOD)%MOD,p[j]=(t2+t)%MOD;
omg=1ll*omg*res%MOD;
}
}
}
if(inv==-1)
{
ll invl=qpow(cnt,MOD-2);
for(register int i=0;i<=cnt;i++)
{
cp[i]=1ll*cp[i]*invl%MOD;
}
}
}
inline void inv(ll fd,ll *f,ll *res)
{
static ll tmp[MAXN];
if(fd==1)
{
res[0]=qpow(f[0],MOD-2);
return;
}
inv((fd+1)>>1,f,res);
ll cnt=1,limit=-1;
while(cnt<(fd<<1))
{
cnt<<=1,limit++;
}
for(register int i=0;i<cnt;i++)
{
tmp[i]=i<fd?f[i]:0;
rev[i]=(rev[i>>1]>>1)|((i&1)<<limit);
}
NTT(tmp,cnt,1),NTT(res,cnt,1);
for(register int i=0;i<cnt;i++)
{
res[i]=1ll*(2-1ll*tmp[i]*res[i]%MOD+MOD)%MOD*res[i]%MOD;
}
NTT(res,cnt,-1);
for(register int i=fd;i<cnt;i++)
{
res[i]=0;
}
}
inline void mod(ll *f)
{
static ll tmp[MAXN],q[MAXN];
ll deg=fd<<1;
while(!f[--deg]);
if(deg<fd)
{
return;
}
for(register int i=0;i<cnt;i++)
{
tmp[i]=i<=deg?f[i]:0;
}
reverse(tmp,tmp+1+deg);
for(register int i=deg+1-fd;i<=deg;i++)
{
tmp[i]=0;
}
NTT(tmp,cnt,1);
for(register int i=0;i<cnt;i++)
{
q[i]=(li)tmp[i]*tmp3[i]%MOD;
}
NTT(q,cnt,-1);
for(register int i=0;i<cnt;i++)
{
tmp[i]=0;
q[i]=i<=deg-fd?q[i]:0;
}
reverse(q,q+1+deg-fd),NTT(q,cnt,1);
for(register int i=0;i<cnt;i++)
{
tmp[i]=(li)q[i]*g[i]%MOD;
}
NTT(tmp,cnt,-1);
for(register int i=0;i<fd;i++)
{
f[i]=(f[i]-tmp[i]+MOD)%MOD;
}
for(register int i=0;i<cnt;i++)
{
q[i]=tmp[i]=0,f[i]=i<fd?f[i]:0;
}
}
vector<li>bmf[MAXN];
inline void BerlekampMassey(ll length,ll *base,ll *res)
{
ll cur=0;
for(register int i=1;i<=length;i++)
{
li curr=base[i];
for(register int j=0;j<bmf[cur].size();j++)
{
curr=(curr-(li)base[i-j-1]*bmf[cur][j]%MOD)%MOD;
}
delta[i]=curr;
if(!delta[i])
{
continue;
}
fail[cur]=i;
if(!cur)
{
bmf[++cur].resize(i),delta[i]=base[i];
continue;
}
ll id=cur-1,x=bmf[id].size()-fail[id]+i;
for(register int j=0;j<cur;j++)
{
if(i-fail[j]+bmf[j].size()<x)
{
id=j,x=i-fail[j]+bmf[j].size();
}
}
bmf[cur+1]=bmf[cur],cur++;
while(bmf[cur].size()<x)
{
bmf[cur].push_back(0);
}
li mul=(li)delta[i]*qpow(delta[fail[id]],MOD-2)%MOD;
bmf[cur][i-fail[id]-1]=(li)(bmf[cur][i-fail[id]-1]+mul)%MOD;
for(register int j=0;j<bmf[id].size();j++)
{
ll t=(li)mul*bmf[id][j]%MOD;
bmf[cur][i-fail[id]+j]=(bmf[cur][i-fail[id]+j]-t+MOD)%MOD;
}
}
ptr=cur;
for(register int i=0;i<bmf[cur].size();i++)
{
res[i+1]=(bmf[cur][i]%MOD+MOD)%MOD;
}
}
int main()
{
fd=read();
exponent=0;
for(register int i=0;i<fd;i++)
{
tbm[i+1]=f[i]=(read()+MOD)%MOD;
}
BerlekampMassey(fd,tbm,tmp);
printf("%d\n",bmf[ptr].size());
for(register int i=1;i<=bmf[ptr].size();i++)
{
//printf("%d ",tmp[i]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 150ms
memory: 105924kb
input:
10000 481761257 325845401 89198273 331256176 423285801 510703206 160079009 805700484 2785453 119847482 4456012 47414124 382685410 463638256 314056646 483110670 723760177 473280072 294639899 965560586 243267953 822936984 475063108 193430844 842374415 125382693 569285769 643640101 548245375 253979925 321137422 807590125 439193916 555824578 695790048 768546711 874232025 722632162 70574178 284940598 933002512 489768439 42054935 599527755 335883097 525622561 239852608 810334714 224789879 472795210 34...
output:
2774
result:
wrong output format Unexpected end of file - int32 expected
Test #2:
score: 0
Wrong Answer
time: 305ms
memory: 282344kb
input:
10000 377957992 230735870 772819998 993198239 360968885 378226178 886315386 228008333 144745061 641762685 397935071 922736446 523431856 488694995 883193240 462320640 141474228 444154151 788323626 661135743 226247281 156277129 85788520 625038763 744947170 913201034 172630470 371511206 832939892 774089636 892909135 823778443 738599520 940107259 74577347 85203293 746264596 43800291 249971562 202824758 476017303 627539207 168727202 495311891 642341759 186369849 667383766 611957481 910693056 73550853...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #3:
score: 0
Wrong Answer
time: 236ms
memory: 282464kb
input:
10000 994467050 345579150 368407658 822508970 227318746 113808913 22746242 348704395 883368358 714835147 503065644 194474178 780502268 433260222 638121661 336797014 636132928 846071542 663037324 142402894 445584362 68372299 510178125 203420803 127227056 914670253 593408957 328806860 390758916 513613113 827410390 923521355 995003710 795081686 801634427 490967992 372528296 375167933 970366517 65886467 293885895 636359793 718289182 389823558 141043510 667346672 216236222 921323471 834733430 1393107...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #4:
score: 0
Wrong Answer
time: 272ms
memory: 283912kb
input:
10000 422321407 874394669 424297648 172859345 273647214 190897162 559947796 449542846 112460126 946375780 984079597 610596519 714558923 347032404 121312306 330426000 149791827 512286657 376940868 713079105 867945071 868579686 620169139 257603123 893494417 452555681 888893820 442451361 47755329 941802786 542023749 142507278 729310251 662742358 932153689 819038977 516565359 899041903 667898540 853352691 984625734 438809741 973471926 965509551 846158116 677947905 322574625 905010866 141984395 50330...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #5:
score: 0
Wrong Answer
time: 218ms
memory: 282436kb
input:
10000 284535580 904733529 407516463 760176463 12497548 96996750 326237736 770765595 804123903 917411039 82310503 272960190 933904784 296938585 447657802 84352574 461473873 894856552 567017606 799210461 369489990 708397386 7757883 181367404 605182665 225382946 187583443 395599958 746823867 809189320 327153032 588054644 879238188 651507757 686215659 633748789 487973095 690994032 936971696 61126298 287191454 768482238 301504937 183008920 328030151 597050092 61951354 50900113 490469971 21584230 7728...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #6:
score: 0
Wrong Answer
time: 258ms
memory: 281952kb
input:
10000 143402562 710493128 887681468 532235816 11250361 343965675 646233797 181000080 666275055 946724519 145129714 10485344 98155157 537369885 832915199 98115788 710792633 109334564 1763953 506332992 872077306 162316709 677083289 384734909 405706417 907445544 890927000 402847518 315194042 173085581 492921236 837985923 457623852 817206051 134022434 839540857 393155306 47882810 732036497 77045705 388025130 353691140 25567017 58993560 703393601 901462005 908488688 359466827 654239165 777220133 5414...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #7:
score: 0
Wrong Answer
time: 247ms
memory: 283160kb
input:
10000 52647847 844512611 280928302 751557005 420466432 861986872 267896994 4240313 817817481 927655515 851858557 870133599 198036189 805740294 140712607 921128264 844983674 978125074 888858650 948450794 687344982 737245781 339660667 541639603 892892906 50615330 216916882 220287793 633969604 252242878 80671901 740662910 5600251 383006687 527290834 124328197 903221094 74281453 903608149 843060512 606893550 704161422 277214014 411999188 608332575 614062772 15108449 328906302 810964884 898408069 527...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #8:
score: 0
Wrong Answer
time: 252ms
memory: 282024kb
input:
10000 487583046 344693028 826880083 929392262 867951520 408064391 400765869 73124285 895519401 1134312 626909117 156750276 216501935 876445227 142304635 290995429 372199598 28663296 402137325 927614574 350671865 210948669 825856676 215108238 134526265 197222945 164795341 196100988 468597412 566453293 490377012 209795322 858515618 587275566 317659491 413804329 429078204 922871210 299586381 30597051 915577123 184301950 962406897 788403457 598350678 418184586 447860331 248804953 492851830 140854215...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #9:
score: 0
Wrong Answer
time: 317ms
memory: 282364kb
input:
10000 522870486 728596067 342867687 773337741 995805742 913938215 693740993 719822271 646825737 560772154 902322257 186022837 683085684 810001222 351663644 301237456 965053493 776973140 453390057 342680011 159514296 171302654 909396470 78871368 576640309 310207930 237909277 559788088 536043927 772346209 180750482 684092163 386867317 271698289 150104595 984522691 361571164 539864592 423941221 373478433 866164603 361103790 885090329 257602452 464102311 948167272 633421166 777212175 45871875 366159...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #10:
score: 0
Wrong Answer
time: 317ms
memory: 282528kb
input:
10000 957725520 854846291 969491053 356250398 691705616 213195336 580768790 67132468 874683049 587263928 159905787 591245052 44365380 800142401 225588361 208452961 739469465 130683730 284272807 107327163 183355931 936856467 6990073 292261808 892473264 530135765 586566900 505038785 964987342 629588720 498998636 60420455 479770532 210220226 568202875 173749381 532108012 523361856 556638190 765143957 454192091 252876266 275113383 951761418 57488739 904828258 550297976 32094906 216285909 377075129 6...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #11:
score: 0
Wrong Answer
time: 263ms
memory: 283068kb
input:
10000 468567402 615227461 825790121 924536374 466843001 364872472 35783838 961206768 601425855 669469693 62533267 931605325 103463216 694776506 491182366 643726023 831922439 24457246 734138378 688617551 395538864 825956960 628023036 153322223 40900393 729283507 371038750 903379206 201996039 149486783 53069197 738339562 256111516 965763417 346356310 74045911 567299344 570963600 865091129 978925519 298313396 780074522 357673663 367927945 815706943 251710524 886455569 273643032 354783112 731095410 ...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #12:
score: 0
Wrong Answer
time: 287ms
memory: 281984kb
input:
10000 69862984 293611926 403004942 463746003 659628869 670460967 974517991 836756407 872315054 303957729 818948017 132026024 608732344 851995441 921247689 300940657 282980343 533588021 231159141 115601907 161346426 965077118 434900526 804152885 533402643 800086212 897870234 659037755 680872901 652253708 696579317 272664795 601017450 380042003 358927654 885372241 762611204 559298954 606719395 20550007 878254488 465385966 293317564 978079060 255528868 723646688 819561229 751578678 284152591 219815...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #13:
score: 0
Wrong Answer
time: 285ms
memory: 282532kb
input:
10000 302610832 195739555 615926253 945276664 433921214 311571850 628494857 599350354 254090811 942941793 189235408 988101968 858805828 827202076 722754803 149002706 299639408 232447563 578318640 74552395 281140007 322226109 905781990 803107348 319318654 214252035 766487192 661593943 700418938 307267978 179099212 848259548 178201573 605562279 823638265 664902340 328764672 151257732 324315399 28528039 355445523 37036717 393161332 28497604 518268512 583724281 120930378 635671858 380746968 89476091...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #14:
score: 0
Wrong Answer
time: 286ms
memory: 282680kb
input:
10000 194896228 365691994 70573349 52066983 251370641 592635286 802370214 371278914 534032008 470173258 818664030 633926171 148741371 375736605 776542446 937276745 742949876 77010768 900860596 707193546 862212465 211006831 177123515 903854249 413455739 375289098 531661615 604267091 797158809 890908982 45472935 716606604 55238337 99962855 427685741 60701548 100658386 336051316 993314919 435559954 985485921 21455570 972740541 899099391 777255902 643342788 826229428 292483091 729001423 137196113 22...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #15:
score: 0
Wrong Answer
time: 240ms
memory: 282044kb
input:
10000 173682722 823239462 497261788 898490895 314555842 291743840 613638047 537082136 503296908 440934740 696542803 824708774 566603947 485620288 300818184 921570494 375405522 250256317 338078768 267431337 658768476 575964387 951479366 104388069 431325614 792083015 145946469 191033122 507972995 886029372 532751171 172869243 793574054 364371334 120843486 275039951 273382809 641601468 757601815 872222212 73071379 22740240 773794092 702526984 885736429 45767417 40595042 901913552 325624892 14093873...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #16:
score: 0
Wrong Answer
time: 295ms
memory: 282808kb
input:
10000 180872957 339943670 923666064 417992982 339533575 775349576 329510000 145625425 573569765 211500590 566445810 792794434 591183709 175028313 71864328 205913803 412983706 877885019 215279970 819322422 506671586 833345512 699039480 622660968 476099555 475758623 612686236 856117219 759055458 1586656 707125046 4277640 954636217 252013646 313676451 790768650 55477398 542806867 43842310 621107240 572601125 543919804 957149458 430289742 75281751 924597531 722842566 972760498 259813509 298051202 51...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #17:
score: 0
Wrong Answer
time: 302ms
memory: 282644kb
input:
10000 291189140 310412941 109147063 234599709 330358548 245178015 187231724 118497705 670984353 875636623 681806958 827074754 646536850 515308282 940260328 708983658 355335611 996527156 803147102 65525572 498477971 694445854 673857882 352662978 215416891 937755117 586731991 970486963 116242599 805917235 741113156 460740787 941948067 599555209 513205084 690037147 439330191 104534389 735577626 220492154 215797221 890767530 978465174 188082073 490156347 714845837 194907291 834103363 560948552 66195...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #18:
score: 0
Wrong Answer
time: 293ms
memory: 282328kb
input:
10000 99628167 17871381 477754729 823487682 163833037 443497093 877969926 901793571 265264653 557880451 253335762 503940775 965234905 635123159 841382197 666022146 667190979 864511439 625446884 729504121 579523530 534312522 204572066 747448465 88325700 392039741 342065376 128926252 143283083 952454094 515368570 436496086 903277902 588084238 439375407 688488862 396155240 909603502 286511947 973201205 524158466 586721448 828849928 638262500 222216444 325187310 395288117 468102961 438997029 4506937...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #19:
score: 0
Wrong Answer
time: 243ms
memory: 283340kb
input:
10000 981720654 486851988 423085817 305424429 229274760 911398813 54273722 516498837 168853392 505136195 418929257 769673344 430797694 908076834 651077186 624043582 612492865 137464577 577117295 3077674 246604333 570755320 164513746 949001351 256474379 182695561 9496924 395282535 444743691 724782360 117254905 585129666 630219206 198851268 867031680 779766976 691494901 39027424 379721405 156158191 186420036 492656474 209653017 833245345 641209783 167405248 34235599 700323288 497495958 451093027 3...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected
Test #20:
score: 0
Wrong Answer
time: 277ms
memory: 282940kb
input:
10000 915846929 265862453 90423096 243585370 971578883 885628335 460190028 120633820 699582999 765042464 717239292 217866398 939707644 488047543 956758075 673960306 741412460 928085904 638426299 810463610 514252660 540402624 475692835 969861072 574746419 815272205 226039098 180344861 450371329 193908222 73703120 347643885 922857770 403674008 845057476 490032147 116402286 296724696 886055452 581784879 589104832 763955971 180617579 655005496 747129238 478795017 865115664 408790816 140158688 270931...
output:
5000
result:
wrong output format Unexpected end of file - int32 expected