QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188375 | #5743. Palindromic Polynomial | 275307894a | TL | 982ms | 4352kb | C++14 | 2.4kb | 2023-09-25 19:31:04 | 2023-09-25 19:31:04 |
Judging History
answer
#include<bits/stdc++.h>
#define Me(x,y) memset(x,y,sizeof x)
#define Mc(x,y) memcpy(x,y,sizeof x)
using ll=long long;
#define fi first
#define se second
using namespace std;
const int N=1e4+5,M=N*N*2+5,mod=1e9+9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,k,x,y,z,Qh,YAI;
pair<int,int> P[N],Q[N];
ll mpow(ll x,int y=mod-2){ll Ans=1;while(y) y&1&&(Ans=Ans*x%mod),y>>=1,x=x*x%mod;return Ans;}
#define FAIL {puts("-1");return;}
ll f[N],g[N],A0,p[N];
int Find(int d);
int calc(int d){
Qh=n;int i,j;for(i=1;i<=n;i++) Q[i]=P[i];
for(i=1;i<=n;i++) if(P[i].fi) Q[++Qh]={mpow(P[i].fi),P[i].se*mpow(mpow(P[i].fi),d)%mod};
sort(Q+1,Q+Qh+1);for(i=2;i<=Qh;i++) if(Q[i].fi==Q[i-1].fi&&Q[i].se^Q[i-1].se) return 0;
if(YAI) return 0;YAI=1;
Qh=unique(Q+1,Q+Qh+1)-Q-1;
Me(f,0);Me(g,0);f[0]=1;for(i=1;i<=Qh;i++) for(j=Qh;~j;j--) f[j]=(f[j]*(mod-Q[i].fi)+(j?f[j-1]:0))%mod;
for(i=1;i<=Qh;i++){
ll Iv=mpow(mod-Q[i].fi);
for(j=0;j<=Qh;j++) f[j]=(f[j]-(j?f[j-1]:0)+mod)%mod*Iv%mod;
ll Ts=1;for(j=1;j<=Qh;j++) if(i^j)Ts=Ts*(Q[i].fi-Q[j].fi+mod)%mod;
Ts=mpow(Ts)*Q[i].se%mod;
for(j=0;j<=Qh;j++) g[j]=(g[j]+f[j]*Ts)%mod;
for(j=Qh;~j;j--) f[j]=(f[j]*(mod-Q[i].fi)+(j?f[j-1]:0))%mod;
}
for(i=d+1;i<=Qh;i++) if(g[i]) return 0;
Mc(p,g);for(i=0;i<=d;i++) p[d-i]=(p[d-i]+g[i])%mod*(mod+1)/2%mod;
// for(i=0;i<=d;i++) cerr<<p[i]<<' ';cerr<<'\n';
if(A0==-1&&!p[0]) {
for(i=d+1;i<=Qh;i++) if(f[i]) return 0;
for(i=0;i<=d;i++) p[i]=(p[i]+f[i])%mod,p[d-i]=(p[d-i]+f[i])%mod;
}else if(~A0&&p[0]^A0){
for(i=d+1;i<=Qh;i++) if(f[i]) return 0;
// for(i=0;i<=d;i++) cerr<<f[i]<<' ';cerr<<'\n';
if((f[0]+f[d])%mod==0) return 0;
ll s=(A0-p[0]+mod)%mod*mpow(f[0]+f[d])%mod;
for(i=0;i<=d;i++) p[i]=(p[i]+f[i]*s)%mod,p[d-i]=(p[d-i]+f[i]*s)%mod;
}
if(!p[d]) return 0;
printf("%d\n",d);
for(i=0;i<=d;i++) printf("%lld ",p[i]);
printf("\n");return 1;
}
void Solve(){
int i,j;scanf("%d",&n);cerr<<n<<'\n';for(i=1;i<=n;i++) scanf("%d",&P[i].fi),cerr<<P[i].fi<<' ';cerr<<'\n';for(i=1;i<=n;i++) scanf("%d",&P[i].se),cerr<<P[i].se<<' ';cerr<<'\n';
A0=-1;Qh=0;YAI=0;for(i=1;i<=n;i++) if(P[i].fi) Q[++Qh]=P[i];else if(A0==-1) A0=P[i].se;else if(A0!=P[i].se) FAIL;Mc(P,Q);n=Qh;
for(i=1e4;i;i--){
if(calc(i)) return ;
}
puts("-1");
}
int main(){
int t;scanf("%d",&t);while(t--) Solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 26ms
memory: 4284kb
input:
8 2 0 1 2 4 3 0 1 2 2 10 36 4 0 1 2 3 1 4 9 16 5 0 1 2 3 4 1 25 961 14641 116281 2 2 500000005 5 375000004 2 2 500000005 5 375000004 2 2 500000005 1 2 3 2 500000005 3 5 375000004 10
output:
10000 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok OK (8 test cases)
Test #2:
score: 0
Accepted
time: 11ms
memory: 4352kb
input:
10 100 24820 26839 18512 6097 25046 22372 21548 2359 17721 9732 16436 12710 14995 4112 17855 28268 28129 13501 23470 16561 8633 29875 13119 10835 15842 14515 5588 10553 28603 3849 12379 17065 15155 15079 26029 3003 2878 29555 3609 8886 2841 17696 9648 4533 5924 12557 25988 29061 26075 28447 28620 20...
output:
10000 991763663 84183251 817748541 751820472 274705299 514844809 913324462 820197929 612599255 544464585 308799257 597748867 819625620 166080135 361705698 661132829 605251716 496947604 920996634 950546155 264960302 137225471 323125051 668269766 400370855 394998826 746252932 404806900 592103371 32196...
result:
ok OK (10 test cases)
Test #3:
score: 0
Accepted
time: 69ms
memory: 4300kb
input:
1 1000 112 16069 28329 8759 23521 1674 11755 9574 19846 5769 27729 17604 3648 29441 25349 24311 6088 2549 6437 16310 25464 25775 20988 21334 3451 1098 26971 3856 28015 24136 18147 24690 4690 4517 14412 29017 14675 5027 18071 4428 29328 28568 12161 2780 23653 21472 21227 23968 1331 24977 7243 13552 6...
output:
10000 595082465 500379518 192552113 852814130 247309815 962855771 99418958 331067561 535148608 579727297 259903516 111909078 37735507 500838722 255719385 725870731 519455673 56193620 436557088 32184394 483678212 529399895 706324015 477741359 718334153 959571726 408401068 308036831 271560940 58661475...
result:
ok OK (1 test case)
Test #4:
score: 0
Accepted
time: 386ms
memory: 4300kb
input:
21 8 1000000008 191950673 311042534 341446923 351508511 730849637 837221839 949983050 2 199758730 296525790 620719636 271569769 48989015 768611306 77253955 8 1 6208459 29989762 187741303 265062278 393002943 957915451 986759042 2 603327752 901822821 349826936 933716294 123962049 672761843 702453404 8...
output:
8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 1 0 0 0 0 0 0 0 1 8 2 271354657 891205111 165061237 938035001 165061237 891205111 271354657 2 8 1 0 0 0 0 0...
result:
ok OK (21 test cases)
Test #5:
score: 0
Accepted
time: 386ms
memory: 4236kb
input:
21 8 1000000008 82536156 95733833 173997609 176779824 454444312 524861364 586834996 4 841461190 384072747 954440743 152490383 894790857 441089967 851188211 8 1 62386922 117616238 344901582 692317472 798339321 934650757 967500526 4 923589217 91616771 328945919 250367604 465360899 562911768 673536418 ...
output:
8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 2 0 0 0 0 0 0 0 2 8 172714825 160877285 386074618 89808869 3837934...
result:
ok OK (21 test cases)
Test #6:
score: 0
Accepted
time: 440ms
memory: 4152kb
input:
21 9 72520483 109296160 328830012 427629800 496439117 517407888 723526448 875376334 984205010 513501309 405430695 97038420 80044690 244607478 420952403 730491956 655670564 934113242 9 1000000008 1 196696216 367187687 520201124 575456207 634588206 768006032 938587173 0 2 305160038 629977990 316645777...
output:
9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 1 9 2 979850011 736731106 822763841 949716086 949716086 822763841 736731...
result:
ok OK (21 test cases)
Test #7:
score: 0
Accepted
time: 440ms
memory: 4280kb
input:
21 9 7776991 170135976 184357477 364912922 393159207 671848154 694727065 726096468 807558271 931408489 76229428 359286772 482810970 983371544 900415283 988630700 476855584 692102868 9 1000000008 1 254616697 350933937 613951686 792090796 806204674 896604470 996266271 0 4 296124300 133457045 889008814...
output:
9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 2 0 0 0 0 0 0 0 0 2 9 950596433 398428511 75...
result:
ok OK (21 test cases)
Test #8:
score: 0
Accepted
time: 386ms
memory: 4208kb
input:
21 8 1000000008 293188747 506560951 728885372 795956429 838708555 880755953 954756300 1 931650696 717763978 59630926 173745195 741697269 899703391 234180638 8 1 46322566 407158342 509723817 636040242 738500416 759476271 948754709 25 216101899 119160932 343194015 57776340 157262836 276807561 33982633...
output:
8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 1 2 3 4 5 4 3 2 1 8 2 217761262 204058746 261876141 1809657 261876141 204058746 217761262 2 8 1 2 3 4 5 4 3...
result:
ok OK (21 test cases)
Test #9:
score: 0
Accepted
time: 441ms
memory: 4336kb
input:
21 9 75218911 90366076 119101189 194246800 350541227 377200962 818012261 895921660 966585262 732955481 335776396 765729084 902489414 875573484 526286992 675327718 219549932 52753284 9 1000000008 1 121073903 135154924 206002108 693217175 709348851 800428289 922910175 0 30 110846868 369125846 78199011...
output:
9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 1 2 3 4 5 5 4 3 2 1 9 2 22957518 473433506 339131525 865282871 865282871 339131525 4734335...
result:
ok OK (21 test cases)
Test #10:
score: 0
Accepted
time: 494ms
memory: 4344kb
input:
21 10 1000000008 12260195 80754602 163716464 312829272 391611827 673741746 728563133 811628297 911803655 0 235646491 746092480 793242180 563675433 190413403 995430294 304276112 911389010 347436328 10 1 18892100 71240811 234644042 405445374 537145743 553798351 572060490 726412557 875107448 36 5419823...
output:
10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 1 2 3 4 5 6 5 4 3 2 1 10 2 354588207 109646242 889269033 31658...
result:
ok OK (21 test cases)
Test #11:
score: 0
Accepted
time: 755ms
memory: 4216kb
input:
21 15 102902010 104440499 141407938 254801315 302108881 375503505 483498247 569424584 631076513 674425009 710414727 748037505 787597696 897754981 913961979 750445007 723764181 522261770 384970598 466582584 399445938 304490242 178761561 97731177 711994375 711199040 109300424 225657734 328363283 70380...
output:
15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 15 33 16 52 95 8 73 90 18 18 90 73 8 95 52 16 33 ...
result:
ok OK (21 test cases)
Test #12:
score: 0
Accepted
time: 764ms
memory: 4160kb
input:
21 15 190238676 408903599 473934421 488621309 500829135 684814169 779979654 813377310 866962260 874120900 882901969 929880722 939256395 956209677 995016475 508631129 882709950 185145270 713649239 983567479 998524204 67708788 859291 999492696 130232703 891966111 441494490 332533393 703135760 64268444...
output:
15 18 81 81 16 58 48 71 18 18 71 48 58 16 81 81 18 15 18 81 81 16 58 48 71 18 18 71 48 58 16 81 81 18 15 18 81 81 16 58 48 71 18 18 71 48 58 16 81 81 18 15 18 81 81 16 58 48 71 18 18 71 48 58 16 81 81 18 15 18 81 81 16 58 48 71 18 18 71 48 58 16 81 81 18 15 18 81 81 16 58 48 71 18 18 71 48 58 1...
result:
ok OK (21 test cases)
Test #13:
score: 0
Accepted
time: 972ms
memory: 4204kb
input:
21 19 26294376 70967317 135772333 163164758 190196450 190331407 263742305 289352143 294421555 384429498 404563902 421898751 501143739 558923946 663294565 687319026 754424225 840450575 911028598 260487108 14726161 703228508 619949324 417344016 544228071 953555078 345998205 557232429 191999681 4600517...
output:
19 96 23 54 68 33 62 84 100 26 18 18 26 100 84 62 33 68 54 23 96 19 96 23 54 68 33 62 84 100 26 18 18 26 100 84 62 33 68 54 23 96 19 96 23 54 68 33 62 84 100 26 18 18 26 100 84 62 33 68 54 23 96 19 96 23 54 68 33 62 84 100 26 18 18 26 100 84 62 33 68 54 23 96 19 96 23 54 68 33 62 84 100 26 18 18...
result:
ok OK (21 test cases)
Test #14:
score: 0
Accepted
time: 982ms
memory: 4280kb
input:
21 19 65433256 203120539 230619032 242339653 306408928 319892667 358753761 406955804 456020246 568215116 658002035 667809083 713920687 758560518 792203516 826915826 868910207 947222195 979951831 710093141 609738169 294821300 319884586 559809243 118163813 202242806 53046643 383830818 669518255 473578...
output:
19 28 54 85 91 50 30 65 94 27 59 59 27 94 65 30 50 91 85 54 28 19 28 54 85 91 50 30 65 94 27 59 59 27 94 65 30 50 91 85 54 28 19 28 54 85 91 50 30 65 94 27 59 59 27 94 65 30 50 91 85 54 28 19 28 54 85 91 50 30 65 94 27 59 59 27 94 65 30 50 91 85 54 28 19 28 54 85 91 50 30 65 94 27 59 59 27 94 65...
result:
ok OK (21 test cases)
Test #15:
score: 0
Accepted
time: 980ms
memory: 4156kb
input:
21 19 94730190 98406141 117177150 151885244 178905728 222257031 349187661 384666078 386234223 455425437 470266682 722168666 809818898 835948150 860749403 917499921 934399177 956526573 989637011 303082625 162132429 408192664 585973108 271970371 500211566 129010096 685239539 653965708 393652022 994078...
output:
19 50 91 94 78 86 62 66 32 36 9 9 36 32 66 62 86 78 94 91 50 19 50 91 94 78 86 62 66 32 36 9 9 36 32 66 62 86 78 94 91 50 19 50 91 94 78 86 62 66 32 36 9 9 36 32 66 62 86 78 94 91 50 19 50 91 94 78 86 62 66 32 36 9 9 36 32 66 62 86 78 94 91 50 19 50 91 94 78 86 62 66 32 36 9 9 36 32 66 62 86 78 ...
result:
ok OK (21 test cases)
Test #16:
score: -100
Time Limit Exceeded
input:
1 1000 1000000008 1163314 1725881 1859188 1927255 4342530 4578730 4746103 5123392 5506632 6230591 7566874 8086831 8637758 8890521 9139570 9965029 10373127 11912148 12953170 13042845 14260540 14474386 14647027 16719219 17143558 17206396 17598422 18621675 19116034 20547451 20737458 20849209 21344486 2...