QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#260319 | #5743. Palindromic Polynomial | Crysfly | WA | 0ms | 4416kb | C++17 | 4.2kb | 2023-11-22 01:24:20 | 2023-11-22 01:24:21 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000009
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 20005
#define inf 0x3f3f3f3f
int n,d;
modint x[maxn],y[maxn];
pair<modint,modint>tmp[maxn];
modint now[maxn];
int cnt;
modint f[maxn];
namespace F{
int l=0;
modint x[maxn],y[maxn],a[maxn];
int n;
void mul(modint b){
++l,a[l]=0;
Rep(i,l,1)a[i]=a[i]*b+a[i-1];
a[0]*=b;
}
void div(modint b){
modint iv=1/b;
a[0]*=iv;
For(i,1,l)a[i]-=a[i-1],a[i]*=iv;
--l;
}
void wk(){
l=0,a[l]=1;
memset(a,0,sizeof a);
a[l]=1;
memset(f,0,sizeof f);
// For(i,1,n)cout<<x[i].x<<" "<<y[i].x<<"\n"; cout<<"----\n";
For(i,1,n)mul(-x[i]);
For(i,1,n){
modint coef=1;
For(j,1,n)if(i!=j)coef*=x[i]-x[j];
coef=y[i]/coef;
div(-x[i]);
For(j,0,n-1)f[j]+=a[j]*coef;
mul(-x[i]);
}
For(i,0,n+1)cout<<f[i].x<<" ";cout<<"\n";
}
}
modint res[maxn],res2[maxn];
void work()
{
n=read();
For(i,1,n)x[i]=read(),y[i]=read();
For(i,1,n)For(j,i+1,n)
if((x[i]*x[j]).x==1){
if(y[i].x||y[j].x)
tmp[++cnt]=mkp(x[i],y[i]/y[j]);
}
if(!cnt) d=n*2;
else{
d=-1;
For(i,1,cnt)now[i]=1;
For(i,0,10000){
bool ok=1;
For(j,1,cnt){
ok&=(now[i].x==tmp[i].se.x);
now[i]*=tmp[i].fi;
}
}
if(d==-1)return puts("-1"),void();
}
bool hav0=0;
modint y0=1;
map<modint,modint>mp;
For(i,1,n){
if(x[i].x==0){
hav0=1;
y0=y[i];
if(!y0.x)return puts("-1"),void();
continue;
}
mp[x[i]]=y[i];
mp[1/x[i]]=y[i]*(x[i]^(mod-1-d));
}
F::n=0;
for(auto it:mp) ++F::n,F::x[F::n]=it.fi,F::y[F::n]=it.se;
F::wk();
For(i,d+1,10000)
if(f[i].x)return puts("-1"),void();
For(i,0,d) res[i]=(f[i]+f[d-i])*((mod+1)/2);
if((hav0 && res[0].x!=y0.x) || (!hav0 && res[0].x==0)){
modint add=y0-res[0];
For(i,d+1,10000)
if(F::a[i].x)return puts("-1"),void();
For(i,0,d)
res2[i]=(F::a[i]+F::a[d-i])*((mod+1)/2);
add/=res2[0];
For(i,0,d) res[i]+=res2[i]*add;
}
cout<<d<<"\n";
For(i,0,d) cout<<res[i].x<<" "; cout<<"\n";
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
/*
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4416kb
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:
1000000008 500000007 0 0 4 1 500000002 3 500000002 1 757105270 460473688 374013162 103236843 0 0 6 1 399999991 992894774 442763137 992894774 399999991 1 438239910 221972135 13498349 144601429 181688190 0 0 8 1 818776580 977662040 320507812 766107183 320507812 977662040 818776580 1 827912128 57...
result:
wrong answer Integer parameter [name=d] equals to 1000000008, violates the range [-1, 10000] (test case 1)