結果
問題 | No.1025 Modular Equation |
ユーザー | beet |
提出日時 | 2020-04-10 23:08:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,349 bytes |
コンパイル時間 | 3,827 ms |
コンパイル使用メモリ | 220,268 KB |
実行使用メモリ | 198,644 KB |
最終ジャッジ日時 | 2024-09-15 23:54:04 |
合計ジャッジ時間 | 21,631 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} using Int = long long; const char newl = '\n'; template<typename T,T MOD = 1000000007> struct Mint{ static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v <a.v;} static Mint comb(long long n,int k){ Mint num(1),dom(1); for(int i=0;i<k;i++){ num*=Mint(n-i); dom*=Mint(i+1); } return num/dom; } }; template<typename T,T MOD> constexpr T Mint<T, MOD>::mod; template<typename T,T MOD> ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;} namespace FFT{ using dbl = double; struct num{ dbl x,y; num(){x=y=0;} num(dbl x,dbl y):x(x),y(y){} }; inline num operator+(num a,num b){ return num(a.x+b.x,a.y+b.y); } inline num operator-(num a,num b){ return num(a.x-b.x,a.y-b.y); } inline num operator*(num a,num b){ return num(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x); } inline num conj(num a){ return num(a.x,-a.y); } int base=1; vector<num> rts={{0,0},{1,0}}; vector<int> rev={0,1}; const dbl PI=asinl(1)*2; void ensure_base(int nbase){ if(nbase<=base) return; rev.resize(1<<nbase); for(int i=0;i<(1<<nbase);i++) rev[i]=(rev[i>>1]>>1)+((i&1)<<(nbase-1)); rts.resize(1<<nbase); while(base<nbase){ dbl angle=2*PI/(1<<(base+1)); for(int i=1<<(base-1);i<(1<<base);i++){ rts[i<<1]=rts[i]; dbl angle_i=angle*(2*i+1-(1<<base)); rts[(i<<1)+1]=num(cos(angle_i),sin(angle_i)); } base++; } } void fft(vector<num> &as){ int n=as.size(); assert((n&(n-1))==0); int zeros=__builtin_ctz(n); ensure_base(zeros); int shift=base-zeros; for(int i=0;i<n;i++) if(i<(rev[i]>>shift)) swap(as[i],as[rev[i]>>shift]); for(int k=1;k<n;k<<=1){ for(int i=0;i<n;i+=2*k){ for(int j=0;j<k;j++){ num z=as[i+j+k]*rts[j+k]; as[i+j+k]=as[i+j]-z; as[i+j]=as[i+j]+z; } } } } template<typename T> vector<long long> multiply(vector<T> &as,vector<T> &bs){ int need=as.size()+bs.size()-1; int nbase=0; while((1<<nbase)<need) nbase++; ensure_base(nbase); int sz=1<<nbase; vector<num> fa(sz); for(int i=0;i<sz;i++){ T x=(i<(int)as.size()?as[i]:0); T y=(i<(int)bs.size()?bs[i]:0); fa[i]=num(x,y); } fft(fa); num r(0,-0.25/sz); for(int i=0;i<=(sz>>1);i++){ int j=(sz-i)&(sz-1); num z=(fa[j]*fa[j]-conj(fa[i]*fa[i]))*r; if(i!=j) fa[j]=(fa[i]*fa[i]-conj(fa[j]*fa[j]))*r; fa[i]=z; } fft(fa); vector<long long> res(need); for(int i=0;i<need;i++) res[i]=round(fa[i].x); return res; } }; template<typename T> struct ArbitraryMod{ using dbl=FFT::dbl; using num=FFT::num; vector<T> multiply(vector<T> as,vector<T> bs){ int need=as.size()+bs.size()-1; int sz=1; while(sz<need) sz<<=1; vector<num> fa(sz),fb(sz); for(int i=0;i<(int)as.size();i++) fa[i]=num(as[i].v&((1<<15)-1),as[i].v>>15); for(int i=0;i<(int)bs.size();i++) fb[i]=num(bs[i].v&((1<<15)-1),bs[i].v>>15); fft(fa);fft(fb); dbl ratio=0.25/sz; num r2(0,-1),r3(ratio,0),r4(0,-ratio),r5(0,1); for(int i=0;i<=(sz>>1);i++){ int j=(sz-i)&(sz-1); num a1=(fa[i]+conj(fa[j])); num a2=(fa[i]-conj(fa[j]))*r2; num b1=(fb[i]+conj(fb[j]))*r3; num b2=(fb[i]-conj(fb[j]))*r4; if(i!=j){ num c1=(fa[j]+conj(fa[i])); num c2=(fa[j]-conj(fa[i]))*r2; num d1=(fb[j]+conj(fb[i]))*r3; num d2=(fb[j]-conj(fb[i]))*r4; fa[i]=c1*d1+c2*d2*r5; fb[i]=c1*d2+c2*d1; } fa[j]=a1*b1+a2*b2*r5; fb[j]=a1*b2+a2*b1; } fft(fa);fft(fb); vector<T> cs(need); using ll = long long; for(int i=0;i<need;i++){ ll aa=T(llround(fa[i].x)).v; ll bb=T(llround(fb[i].x)).v; ll cc=T(llround(fa[i].y)).v; cs[i]=T(aa+(bb<<15)+(cc<<30)); } return cs; } }; template<typename T> struct Rint{ static T mod; static void set_mod(T nmod){mod=nmod;} T v; Rint():v(0){} Rint(signed v):v(v){} Rint(long long t){v=t%mod;if(v<0) v+=mod;} Rint pow(long long k){ Rint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Rint add_identity(){return Rint(0);} static Rint mul_identity(){return Rint(1);} Rint inv(){return pow(mod-2);} Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;} Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;} Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;} Rint& operator/=(Rint a){return (*this)*=a.inv();} Rint operator+(Rint a) const{return Rint(v)+=a;} Rint operator-(Rint a) const{return Rint(v)-=a;} Rint operator*(Rint a) const{return Rint(v)*=a;} Rint operator/(Rint a) const{return Rint(v)/=a;} Rint operator-() const{return v?Rint(mod-v):Rint(v);} bool operator==(const Rint a)const{return v==a.v;} bool operator!=(const Rint a)const{return v!=a.v;} bool operator <(const Rint a)const{return v <a.v;} }; template<typename T> T Rint<T>::mod; template<typename T> ostream& operator<<(ostream &os,Rint<T> m){os<<m.v;return os;} //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int p,n,k,b; cin>>p>>n>>k>>b; vector<int> as(n); for(int i=0;i<n;i++) cin>>as[i]; using R = Rint<int>; R::set_mod(p); vector<R> ps(p); for(int i=0;i<p;i++) ps[i]=R(i).pow(k); using M = Mint<int>; ArbitraryMod<M> arb; using Poly = vector<M>; map<Poly, int> cnt; for(int i=0;i<n;i++){ Poly ad(p,0); for(int j=0;j<p;j++) ad[(R(as[i])*ps[j]).v]+=M(1); cnt[ad]++; } return 0; auto mul=[&](Poly as,Poly bs){ assert((int)as.size()==p); assert((int)bs.size()==p); auto cs=arb.multiply(as,bs); for(int j=p;j<(int)cs.size();j++) cs[j-p]+=cs[j]; cs.resize(p); return cs; }; Poly dp(p,0); dp[0]=1; for(auto tmp:cnt){ Poly ad=tmp.first; int x=tmp.second; while(x){ if(x&1) dp=mul(dp,ad); x>>=1; if(x) ad=mul(ad,ad); } } cout<<dp[b]<<newl; return 0; }