QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322339#5743. Palindromic Polynomialdo_while_trueRE 0ms0kbC++204.8kb2024-02-06 21:20:422024-02-06 21:20:42

Judging History

你现在查看的是最新测评结果

  • [2024-02-06 21:20:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-02-06 21:20:42]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=1000000009;
const int inv2=(mod+1)/2;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
const int N=10010;
struct Lag{
	int n;
	int a[N],b[N];
	int f[N],g[N];
	void clear(int d){n=0;mem(a);mem(b);mem(f);mem(g);}
	void ins(int x,int y){++n;a[n]=x;b[n]=y;}
	void solve(){
		for(int i=0;i<=n;i++)f[i]=g[i]=0;
		f[0]=1;
		for(int i=1;i<=n;i++){
			for(int j=n;j>=1;j--)
				f[j]=del(f[j-1],1ll*a[i]*f[j]%mod);
			f[0]=1ll*del(0,a[i])*f[0]%mod;
		}
		for(int i=1;i<=n;i++){
			int t=qpow(del(0,a[i]),mod-2);
			f[0]=1ll*t*f[0]%mod;
			for(int j=1;j<=n;j++){
				cdel(f[j],f[j-1]);
				f[j]=1ll*t*f[j]%mod;
			}
			int s=b[i];
			for(int j=1;j<=n;j++)if(i!=j)s=1ll*s*qpow(del(a[i],a[j]),mod-2)%mod;
			for(int j=0;j<=n;j++)cadd(g[j],1ll*f[j]*s%mod);
			for(int j=n;j>=1;j--)
				f[j]=del(f[j-1],1ll*a[i]*f[j]%mod);
			f[0]=1ll*del(0,a[i])*f[0]%mod;
		}
	}
}lag;
int n;
int a[N],b[N],ok[N];
int ta[N],tb[N];
int f[N],C[N],D[N];
void solve(){
	mem(a);mem(b);mem(ok);
	mem(ta);mem(tb);mem(f);mem(C);mem(D);
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<=n;i++)read(b[i]);
	map<int,int>vis;
	int tot=0,a0=1,ok0=0;
	for(int i=1;i<=n;i++){
		if(vis.count(a[i])){
			if(vis[a[i]]!=b[i]){
				puts("-1");
				return ;
			}
		}
		else{
			vis[a[i]]=b[i];
			if(a[i]==0){
				a0=b[i];ok0=1;
			}
			else{
				++tot;ta[tot]=a[i];tb[tot]=b[i];
			}
		}
	}
	if(a0==0){
		puts("-1");
		return ;
	}
	n=tot;
	for(int i=1;i<=n;i++)a[i]=ta[i],b[i]=tb[i];
	for(int i=0;i<=10000;i++)ok[i]=1;
	int fl=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(1ll*a[i]*a[j]%mod==1){
				int w=b[j];
				for(int k=0;k<=10000;k++){
					if(w!=b[i])ok[k]=0;
					w=1ll*w*a[i]%mod;
					fl=1;
				}
			}
	int d=2*n;
	if(fl){
		d=-1;
		for(int i=2*n;i<=10000;i++)if(ok[i]){d=i;break;}
		if(d==-1){
			for(int i=2*n-1;i>=0;i--)if(ok[i]){d=i;break;}
		}
		if(d==-1){
			puts("-1");
			return ;
		}
	}
	lag.clear(d);
	for(int i=1;i<=n;i++){
		lag.ins(a[i],b[i]);
		int u=qpow(a[i],mod-2);
		if(vis.count(u))continue;
		lag.ins(u,1ll*b[i]*qpow(qpow(a[i],mod-2),d)%mod);
	}
	int m=lag.n;
	lag.solve();
	while(m>=0&&!lag.g[m])--m;
	if(m>d){
		puts("-1");
		return ;
	}
	for(int i=0;i<=d;i++)f[i]=1ll*add(lag.g[i],lag.g[d-i])*inv2%mod,C[i]=0;
	if((ok0&&f[0]!=a0)||(!ok0&&!f[0])){
		C[0]=1;
		for(int i=1;i<=lag.n;i++){
			int x=lag.a[i];
			for(int i=d;i>=1;i--)C[i]=del(C[i-1],1ll*C[i]*x%mod);
			C[0]=1ll*C[0]*del(0,x)%mod;
		}
		for(int i=0;i<=d;i++)D[i]=1ll*add(C[i],C[d-i])*inv2%mod;
		int t=1ll*del(a0,f[0])*qpow(D[0],mod-2)%mod;
		for(int i=0;i<=d;i++)cadd(f[i],1ll*D[i]*t%mod);
	}
	//check
	#define WA do{for(int i=1;i<=n;i++)cerr<<a[i]<<' ';for(int i=1;i<=n;i++)cerr<<b[i]<<' ';assert(0);return ;}while(0)
	for(int i=0;i<=d;i++)if(f[i]!=f[d-i])WA;
	if(!f[0])WA;
	for(int i=1;i<=n;i++){
		int s=0;
		for(int j=d;j>=0;j--)s=add(1ll*s*a[i]%mod,f[j]);
		if(s!=b[i]){
//			dbg(i);
			WA;
		}
	}
	cout<<d<<'\n';
	for(int i=0;i<=d;i++)cout<<f[i]<<' ';
	puts("");
}
signed main(){
//	#ifdef do_while_true
//		assert(freopen("data.in","r",stdin));
//	#endif
	int T;read(T);
	while(T--)solve();	
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:

2
2 0 2 
4
2 999999998 28 999999998 2 
6
1 1000000005 0 10 0 1000000005 1 
8
1 2 3 4 5 4 3 2 1 
3
416666670 541666673 541666673 416666670 
3
416666670 541666673 541666673 416666670 
-1

result: