QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#490751 | #5743. Palindromic Polynomial | ucup-team1525# | WA | 465ms | 7776kb | C++20 | 3.1kb | 2024-07-25 16:20:51 | 2024-07-25 16:20:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3;
const int mod=1e9+9;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int ksm(ll x,int tp,int s=1){
for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
return s;
}
int n;
int x[N+5],y[N+5];
int a[N+5][N+5];
int ans[N+5];
bool work(){
// for(int i=1;i<=n;i++){
// for(int j=0;j<=n+1;j++)
// printf("%d ",a[i][j]);
// puts("");
// }
int now=1;
for(int i=0;i<=n;i++){
int j;
for(j=now;j<=n;j++)
if(a[j][i]) break;
if(j==n+1) continue;
if(now!=j) swap(a[now],a[j]);
int iv=ksm(a[now][i],mod-2);
for(j=now+1;j<=n;j++){
int tmp=1ll*a[j][i]*iv%mod;
for(int k=i;k<=n+1;k++)
a[j][k]=(a[j][k]-1ll*a[now][k]*tmp)%mod;
}
now++;
}
for(int i=now;i<=n;i++)
if(a[i][n+1]) return 0;
// for(int i=1;i<=n;i++){
// for(int j=0;j<=n+1;j++)
// printf("%d ",a[i][j]);
// puts("");
// }
for(int i=now-1,j=n;i;i--){
int k;
for(k=0;k<=n;k++)
if(a[i][k]) break;
while(j>k){
ans[j]=1;
for(int l=i;l;l--)
a[l][n+1]=(a[l][n+1]-1ll*a[l][j]*ans[j])%mod;
j--;
}
ans[k]=ksm(a[i][k],mod-2,a[i][n+1]);
for(int l=i;l;l--)
a[l][n+1]=(a[l][n+1]-1ll*a[l][j]*ans[j])%mod;
j--;
}
for(int i=0;i<=n;i++)
ans[i]=(ans[i]+mod)%mod;
return 1;
}
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&x[i]);
for(int i=1;i<=n;i++)
scanf("%d",&y[i]);
for(int i=1;i<=n;i++)
memset(a[i],0,sizeof a[i]);
for(int i=1;i<=n;i++){
a[i][n+1]=y[i];
int kp=1;
for(int j=0;j<=n;j++){
a[i][j]=add(a[i][j],kp);
kp=1ll*kp*x[i]%mod;
}
for(int j=n+1;j<=2*n;j++){
a[i][2*n-j]=add(a[i][2*n-j],kp);
kp=1ll*kp*x[i]%mod;
}
}
if(work()){
printf("%d\n",2*n);
for(int i=0;i<=n;i++)
printf("%d ",ans[i]);
for(int i=n-1;i>=0;i--)
printf("%d ",ans[i]);
puts("");
return;
}
for(int i=1;i<=n;i++)
memset(a[i],0,sizeof a[i]);
for(int i=1;i<=n;i++){
a[i][n+1]=y[i];
int kp=1;
for(int j=0;j<n;j++){
a[i][j]=add(a[i][j],kp);
kp=1ll*kp*x[i]%mod;
}
for(int j=n;j<2*n;j++){
a[i][2*n-j-1]=add(a[i][2*n-j-1],kp);
kp=1ll*kp*x[i]%mod;
}
}
if(work()){
printf("%d\n",2*n-1);
for(int i=0;i<n;i++)
printf("%d ",ans[i]);
for(int i=n-1;i>=0;i--)
printf("%d ",ans[i]);
puts("");
return;
}
puts("-1");
}
int main(){
int t; scanf("%d",&t);
while(t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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:
4 2 500000004 1 500000004 2 6 2 857142854 642857162 1 642857162 857142854 2 8 1 173195873 943298983 383505158 1 383505158 943298983 173195873 1 10 1 756733947 596607661 681930202 964728228 1 964728228 681930202 596607661 756733947 1 3 111111112 1 1 111111112 3 111111112 1 1 111111112 -1 -1
result:
ok OK (8 test cases)
Test #2:
score: 0
Accepted
time: 7ms
memory: 4272kb
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:
200 523193171 7544146 712637223 37059222 168772960 520075917 715873007 699987676 288136087 647102248 599328896 284887036 691150874 777857736 393634688 46448746 916268409 903240904 189874204 648534721 577003003 331401511 416841259 789432369 497120296 329720265 13217959 168061809 695484384 724770469 2...
result:
ok OK (10 test cases)
Test #3:
score: 0
Accepted
time: 465ms
memory: 7776kb
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:
2000 298446769 13111816 818519594 33880119 478272484 686574438 184010121 118064171 52664731 353578167 389168915 324278257 986412854 218590795 774189224 679905660 840260508 27160762 971675834 115417713 932728477 981958473 987118382 499557133 921199465 304103009 625825580 312770962 633551304 960183427...
result:
ok OK (1 test case)
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3928kb
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:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 8 129934419 320297330 1 1 1 1 1 320297330 129934419 -1
result:
wrong answer Test case 1: there is a solution, but printed -1. (test case 1)