結果
問題 |
No.2272 多項式乗算 mod 258280327
|
ユーザー |
|
提出日時 | 2025-09-22 07:00:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,543 bytes |
コンパイル時間 | 3,235 ms |
コンパイル使用メモリ | 298,964 KB |
実行使用メモリ | 19,884 KB |
最終ジャッジ日時 | 2025-09-22 07:00:12 |
合計ジャッジ時間 | 6,545 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 WA * 6 |
ソースコード
#include<bits/stdc++.h> #if __has_include(<atcoder/all>) #include<atcoder/modint> #endif using namespace std; #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define RDVL(T,n,...) vec<T>__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);lin(__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step) #define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a) #define maybe(p,c) (p?c:remove_cvref_t<decltype(c)>{}) #define binary_operator(op,type) auto operator op(const type&rhs)const{auto copy=*this;return copy op##=rhs;} #define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define use_ml using ml=atcoder::modint; namespace my{ auto&operator>>(istream&i,atcoder::modint&x){int t;i>>t;x=t;return i;} auto&operator<<(ostream&o,const atcoder::modint&x){return o<<(int)x.val();} void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; template<class T>concept modulary=requires(T t){t.mod();}; constexpr auto refs(auto&...a){return array{ref(a)...};} template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} const string space{char(32)}; void lin(auto&...a){(cin>>...>>a);} template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>; } namespace my{ template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;} template<class T>ostream&operator<<(ostream&o,const vector<T>&v){ll n=v.size();fo(i,n)o<<v[i]<<maybe(i<n-1,space);return o;} template<class V>constexpr int depth=0; template<class T>struct core_t_helper{using type=T;}; template<class T>using core_t=core_t_helper<T>::type; template<class V>struct vec; template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;}; template<class T>struct hvec_helper<0,T>{using type=T;}; template<int D,class T>using hvec=hvec_helper<D,T>::type; template<class V>struct vec:vector<V>{ static constexpr int D=depth<V>+1; using C=core_t<V>; using vector<V>::vector; vec(const vector<V>&v):vector<V>(v){} void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]); else { } } ll size()const{return vector<V>::size();} }; template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>; } namespace my{ namespace fft{ using real=double; struct complex{ real x,y; complex()=default; complex(real x,real y):x(x),y(y){} inline complex operator+(const complex &c)const{return complex(x+c.x,y+c.y);} inline complex operator-(const complex &c)const{return complex(x-c.x,y-c.y);} inline complex operator*(const complex &c)const{return complex(x*c.x-y*c.y,x*c.y+y*c.x);} inline complex conj()const{return complex(x,-y);} }; const real PI=acosl(-1); ll base=1; vector<complex>rts={{0,0},{1,0}}; vector<int>fft_rev={0,1}; void ensure_base(int nbase){ if(nbase<=base)return; fft_rev.resize(1<<nbase); rts.resize(1<<nbase); fo(i,1<<nbase)fft_rev[i]=(fft_rev[i>>1]>>1)+((i&1)<<(nbase-1)); while(base<nbase){ real angle=PI*2.0/(1<<(base+1)); fo(i,1<<(base-1),1<<base){ rts[i<<1]=rts[i]; real angle_i=angle*(2*i+1-(1<<base)); rts[(i<<1)+1]=complex(std::cos(angle_i),std::sin(angle_i)); } ++base; } } void fast_fourier_transform(vector<complex>&a,int n){ assert((n&(n-1))==0); int zeros=__builtin_ctz(n); ensure_base(zeros); int shift=base-zeros; fo(i,n)if(i<(fft_rev[i]>>shift))swap(a[i],a[fft_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++){ complex z=a[i+j+k]*rts[j+k]; a[i+j+k]=a[i+j]-z; a[i+j]=a[i+j]+z; } } } } } template<class T>struct arbitrary_mod_convolution{ using real=fft::real; using complex=fft::complex; arbitrary_mod_convolution(){} auto multiply(const vector<T>&a,const vector<T>&b,int need=-1){ if(need==-1)need=a.size()+b.size()-1; int nbase=0; while((1<<nbase)<need)nbase++; fft::ensure_base(nbase); int sz=1<<nbase; vector<complex>fa(sz); fo(i,a.size())fa[i]=complex(a[i].val()&((1<<15)-1),a[i].val()>>15); fft::fast_fourier_transform(fa,sz); vector<complex>fb(sz); if(a==b){ fb=fa; }else{ fo(i,b.size())fb[i]=complex(b[i].val()&((1<<15)-1),b[i].val()>>15); fft::fast_fourier_transform(fb,sz); } real ratio=0.25/sz; complex 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); complex a1=(fa[i]+fa[j].conj()); complex a2=(fa[i]-fa[j].conj())*r2; complex b1=(fb[i]+fb[j].conj())*r3; complex b2=(fb[i]-fb[j].conj())*r4; if(i!=j){ complex c1=(fa[j]+fa[i].conj()); complex c2=(fa[j]-fa[i].conj())*r2; complex d1=(fb[j]+fb[i].conj())*r3; complex d2=(fb[j]-fb[i].conj())*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::fast_fourier_transform(fa,sz); fft::fast_fourier_transform(fb,sz); vector<T>ret(need); fo(i,need){ int64_t aa=llround(fa[i].x); int64_t bb=llround(fb[i].x); int64_t cc=llround(fa[i].y); aa=T(aa).val(),bb=T(bb).val(),cc=T(cc).val(); ret[i]=aa+(bb<<15)+(cc<<30); } return ret; } }; template<class T>struct formal_power_series:vec<T>{ using vec<T>::vec; using fps=formal_power_series; static inline arbitrary_mod_convolution<T>fft; static fps mul(const fps&a,const fps&b){ if constexpr(!modulary<T>){ } else if constexpr(is_same_v<T,atcoder::modint998244353>){ } else return fft.multiply(a,b); } fps&operator*=(const fps&g){return*this=(this->size()&&g.size()?mul(*this,g):fps{});} binary_operator(*,fps) }; template<class T>using fps=formal_power_series<T>; } namespace my{entry void main(){ use_ml ml::set_mod(258280327); LL(N); RDVL(ml,N+1,a); LL(M); RDVL(ml,M+1,b); fps<ml>f(a); fps<ml>g(b); if(a==vec<ml>(N+1)||b==vec<ml>(M+1)){ pp(0); pp(0); return; } auto h=f*g; pp(h.size()-1); pp(h); }}