結果
問題 | No.1145 Sums of Powers |
ユーザー | ytqm3 |
提出日時 | 2022-10-08 17:45:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 14,651 bytes |
コンパイル時間 | 6,872 ms |
コンパイル使用メモリ | 320,540 KB |
実行使用メモリ | 108,732 KB |
最終ジャッジ日時 | 2024-06-22 20:35:14 |
合計ジャッジ時間 | 14,594 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
26,752 KB |
testcase_01 | AC | 37 ms
26,852 KB |
testcase_02 | AC | 51 ms
27,492 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
ソースコード
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> #endif namespace ttl{ using namespace std; using f80=long double; using i64=int64_t; using u64=uint64_t; template<int mod> struct mymodint{ i64 vl; static constexpr i64 get_mod(){ return mod; } i64 val(){ return vl; } mymodint(i64 vl_=0):vl(vl_%mod){} mymodint operator-(){ return (vl==0)?0:mod-vl; } mymodint operator+(mymodint rhs){ return mymodint(*this)+=rhs; } mymodint operator-(mymodint rhs){ return mymodint(*this)-=rhs; } mymodint operator*(mymodint rhs){ return mymodint(*this)*=rhs; } mymodint operator/(mymodint rhs){ return mymodint(*this)/=rhs; } mymodint pow(i64 rhs){ mymodint res=1,now=(*this); while(rhs){ res*=((rhs&1)?now:1),now*=now,rhs>>=1; } return res; } mymodint& operator+=(mymodint rhs){ vl+=rhs.vl,vl-=((vl>=mod)?mod:0); return (*this); } mymodint& operator-=(mymodint rhs){ vl+=((vl<rhs.vl)?mod:0),vl-=rhs.vl; return (*this); } mymodint& operator*=(mymodint rhs){ vl=vl*rhs.vl%mod; return (*this); } mymodint& operator/=(mymodint rhs){ return (*this)*=rhs.pow(mod-2); } bool operator==(mymodint rhs){ return vl==rhs.vl; } bool operator!=(mymodint rhs){ return vl!=rhs.vl; } }; template<u64 mod> using modint= #if __has_include(<atcoder/all>) atcoder::static_modint<mod>; #else mymodint<mod>; #endif template<int mod> std::ostream& operator<<(std::ostream& os,modint<mod> x){ return os<<(x.val()); } template<int mod> std::istream& operator>>(std::istream& is,modint<mod>& x){ i64 t; is>>t,x=t; return is; } template<class T> void scn_(T& a){ cin>>a; } template<class T,class U> void scn_(pair<T,U>& a){ scn_(a.first),scn_(a.second); } template<class T> void scn_(vector<T>& a){ for(auto& v:a){ scn_(v); } } template<class T> void scn_(vector<vector<T>>& a){ for(auto& v:a){ for(auto& u:v){ cin>>u; } } } void scn(){} template<class T,class... Args> void scn(T& n,Args&... args){ scn_(n),scn(args...); } template<class T> void prt_(T a){ cout<<a; } template<class T,class U> void prt_(pair<T,U> a){ cout<<"{"<<a.first<<", "<<a.second<<"}"; } void prt_(f80 a){ printf("%.15Lf",a); } template<class T> void prt(vector<T> a){ for(size_t i=0;i<a.size();++i){ prt_(a[i]); cout<<" \n"[i==a.size()-1]; } } template<class T> void prt(vector<vector<T>> a){ for(auto& v:a){ for(size_t i=0;i<v.size();++i){ cout<<v[i]<<" \n"[i==v.size()-1]; } } } template<class T> void prt(T a){ prt_(a),cout<<"\n"; } template<class T,class... Args> void prt(T a,Args... args){ prt_(a),cout<<" ",prt(args...); } template<class Head,class... Tail> struct multi_dim_vector{ using type=vector<typename multi_dim_vector<Tail...>::type>; }; template<class T> struct multi_dim_vector<T>{ using type=T; }; template<class T,class Arg> vector<T> mvec(int n,Arg&& arg){ return vector<T>(n,arg); } template<class T,class... Args> class multi_dim_vector<Args...,T>::type mvec(int n,Args&&... args){ return typename multi_dim_vector<Args...,T>::type(n,mvec<T>(args...)); } template<class T> void rev(T& a){ reverse(a.begin(),a.end());} template<class T> void srt(T& a){ sort(a.begin(),a.end()); } template<class T> void rsrt(T& a){ sort(a.rbegin(),a.rend()); } template<class T> T revd(T a){ reverse(a.begin(),a.end()); return a; } template<class T> T srtd(T a){ sort(a.begin(),a.end()); return a; } template<class T> T rsrtd(T a){ sort(a.rbegin(),a.rend()); return a; } template<class T> T summ(vector<T> a){ return accumulate(a.begin(),a.end(),T(0)); } template<class T> T maxi(vector<T> a){ return *max_element(a.begin(),a.end()); } template<class T> T mini(vector<T> a){ return *min_element(a.begin(),a.end()); } template<class T> void chmx(T& a,T b){ a=max(a,b); } template<class T> void chmn(T& a,T b){ a=min(a,b); } i64 ppcnt(u64 k){ return __builtin_popcountll(k); } template<class T> T powe(T a,i64 n){ T res=1; while(n){ if(n&1){ res*=a; } a*=a; n/=2; } return res; } i64 powe(i64 a,i64 n,i64 m){ i64 res=1; while(n){ if(n&1){ res=res*a%m; } a=a*a%m; n/=2; } return res; } template<class T> void zip(vector<T>& a){ auto b=srtd(a); b.erase(unique(b.begin(),b.end()),b.end()); map<T,int> mp; for(int i=0;i<b.size();++i){ mp[b[i]]=i; } for(auto& v:a){ v=mp[v]; } } i64 sqrf(i64 n){ i64 ok=0,ng=1e9+5; while(std::abs(ok-ng)>1){ i64 mid=(ok+ng)/2; (mid*mid<=n?ok:ng)=mid; } return ok; } i64 sqrc(i64 n){ i64 ok=1e9+5,ng=0; while(std::abs(ok-ng)>1){ i64 mid=(ok+ng)/2; (mid*mid>=n?ok:ng)=mid; } return ok; } i64 dvf(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a+b-1)/b; } return a/b; } i64 dvc(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a)/b; } return (a+b-1)/b; } vector<int> bfs(vector<vector<int>> G,int v){ int N=G.size(); vector<int> dst(N,-1); queue<int> q; dst[v]=0; q.emplace(v); while(q.size()){ int t=q.front(); q.pop(); for(auto u:G[t]){ if(dst[u]==-1){ dst[u]=dst[t]+1; q.emplace(u); } } } return dst; } vector<i64> dijkstra(vector<vector<pair<int,i64>>>& G,int s){ int N=G.size(); vector<i64> dst(N,1e18); dst[s]=0; priority_queue<pair<i64,int>,vector<pair<i64,int>>,greater<pair<i64,int>>> pq; pq.emplace(0,s); vector<int> f(N); while(pq.size()){ auto [t,u]=pq.top(); pq.pop(); if(f[u]){ continue; } f[u]=1; for(auto [v,w]:G[u]){ if(dst[v]>dst[u]+w){ dst[v]=dst[u]+w; pq.emplace(dst[v],v); } } } return dst; } vector<pair<i64,i64>> pfct(i64 n){ vector<pair<i64,i64>> res; for(i64 i=2;i*i<=n;++i){ if(n%i!=0){ continue; } i64 ex=0; while(n%i==0){ ex++,n/=i; } res.emplace_back(i,ex); } if(n!=1){ res.emplace_back(n,1); } return res; } vector<i64> ediv(i64 n){ vector<i64> res; for(i64 i=1;i*i<=n;++i){ if(n%i!=0){ continue; } res.emplace_back(i); if(i*i!=n){ res.emplace_back(n/i); } } srt(res); return res; } template<class T> struct csm2d{ int n,m; vector<vector<T>> a,c; csm2d(vector<vector<T>> a_):n(a_.size()),m(a_[0].size()),a(a_){ auto b=mvec<T>(n,m+1,0); for(int i=0;i<n;++i){ for(int j=0;j<m;++j){ b[i][j+1]=b[i][j]+a[i][j]; } } c=mvec<T>(n+1,m+1,0); for(int j=0;j<m+1;++j){ for(int i=0;i<n;++i){ c[i+1][j]=c[i][j]+b[i][j]; } } } T operator()(int p,int q,int r,int s){ return c[p][r]-c[p][s]-c[q][r]+c[q][s]; } }; template<class T> auto runlng(T a) -> vector<pair<typename decltype(a)::value_type,i64>>{ int n=a.size(); vector<pair<typename decltype(a)::value_type,i64>> res; typename decltype(a)::value_type now=a[0]; i64 l=1; for(int i=1;i<n;++i){ if(a[i-1]==a[i]){ l++; } else{ res.emplace_back(now,l); now=a[i],l=1; } } res.emplace_back(now,l); return res; } template<class T> struct cmb{ vector<T> fac,ifac; cmb(int mx=3000000):fac(mx+1,1),ifac(mx+1,1){ for(int i=1;i<=mx;++i){ fac[i]=fac[i-1]*i; } ifac[mx]/=fac[mx]; for(int i=mx;i>0;--i){ ifac[i-1]=ifac[i]*i; } } T operator()(int n,int k){ if(n<0||k<0||n<k){ return 0; } return fac[n]*ifac[k]*ifac[n-k]; } }; } using namespace ttl; template<u64 mod3> struct NTT{ static constexpr i64 mod0=1012924417; static constexpr i64 mod1=998244353; static constexpr i64 mod2=924844033; typedef modint<mod0> mint0; typedef modint<mod1> mint1; typedef modint<mod2> mint2; typedef modint<mod3> mint3; mint3 garner_(mint0 r0,mint1 r1,mint2 r2){ mint0 x0=r0.val(); mint1 x1=r0.val(); mint2 x2=r0.val(); mint3 x3=r0.val(); mint1 t0=(r1-x1)/mod0; x0+=mint0(mod0)*t0.val(); x1+=mint1(mod0)*t0.val(); x2+=mint2(mod0)*t0.val(); x3+=mint3(mod0)*t0.val(); mint2 t1=(r2-x2)/(mod0*mod1); x0+=mint0(mod0*mod1)*t1.val(); x1+=mint1(mod0*mod1)*t1.val(); x2+=mint2(mod0*mod1)*t1.val(); x3+=mint3(mod0*mod1)*t1.val(); return x3; } vector<mint3> operator()(vector<mint3> a,vector<mint3> b){ vector<mint0> a0(a.size()),b0(b.size()),c0; vector<mint1> a1(a.size()),b1(b.size()),c1; vector<mint2> a2(a.size()),b2(b.size()),c2; for(size_t i=0;i<a.size();++i){ a0[i]=a[i].val(),a1[i]=a[i].val(),a2[i]=a[i].val(); } for(size_t i=0;i<b.size();++i){ b0[i]=b[i].val(),b1[i]=b[i].val(),b2[i]=b[i].val(); } c0=atcoder::convolution(a0,b0); c1=atcoder::convolution(a1,b1); c2=atcoder::convolution(a2,b2); vector<mint3> res(a.size()+b.size()-1); for(size_t i=0;i<res.size();++i){ res[i]=garner_(c0[i],c1[i],c2[i]); } return res; } }; template<u64 mod> struct FPS{ typedef modint<mod> mint; vector<mint> val; NTT<mod> ntt; FPS():val({0}){} FPS(mint t):val({t}){} FPS(int siz):val(max(1,siz)){} FPS(initializer_list<modint<mod>> init):val(init){} FPS(vector<mint> init):val(init){} mint &operator[](int i){ return val[i]; } int size(){ return val.size(); } void resize(int siz){ val.resize(siz); } FPS& resize_(int siz){ auto tmp=val; tmp.resize(siz); return (*this)=tmp; } FPS operator-(){ for(mint& v:val){ v=mint(0)-v; } return (*this); } FPS& operator+=(mint rhs){ val[0]+=rhs; return (*this); } FPS& operator-=(mint rhs){ val[0]-=rhs; return (*this); } FPS& operator*=(mint rhs){ for(auto& v:val){ v*=rhs; } return (*this); } FPS& operator/=(mint rhs){ for(auto& v:val){ v/=rhs; } return (*this); } FPS operator+(mint rhs){ return FPS(*this)+=rhs; } FPS operator-(mint rhs){ return FPS(*this)-=rhs; } FPS operator*(mint rhs){ return FPS(*this)*=rhs; } FPS operator/(mint rhs){ return FPS(*this)/=rhs; } FPS& operator+=(FPS rhs){ resize(max(this->size(),rhs.size())); for(int i=0;i<int(rhs.size());++i){ (*this)[i]+=rhs[i]; } return (*this); } FPS& operator-=(FPS rhs){ resize(max(this->size(),rhs.size())); for(int i=0;i<int(rhs.size());++i){ (*this)[i]-=rhs[i]; } return (*this); } FPS& operator*=(FPS rhs){ val=ntt(val,rhs.val); return (*this); } FPS& operator/=(FPS rhs){ return (*this)*=rhs.inv(); } FPS& operator>>=(int k){ if(int(val.size())<=k){ return (*this)={0}; } FPS res=val; res.val.erase(res.val.begin(),res.val.begin()+k); return (*this)=res; } FPS& operator<<=(int k){ FPS res=val; res.val.insert(res.val.begin(),k,mint(0)); return (*this)=res; } FPS operator+(FPS rhs){ return FPS(*this)+=rhs; } FPS operator-(FPS rhs){ return FPS(*this)-=rhs; } FPS operator*(FPS rhs){ return FPS(*this)*=rhs; } FPS operator/(FPS rhs){ return FPS(*this)/=rhs; } FPS operator<<(int k){ return FPS(*this)<<=k; } FPS operator>>(int k){ return FPS(*this)>>=k; } FPS shrink(){ for(int i=val.size()-1;i>0;--i){ if(val[i]==0){ val.pop_back(); } else{ break; } } return (*this); } FPS diff_(){ if(val.size()==1){ return (*this)={0}; } FPS f(val.size()-1); for(size_t i=1;i<val.size();++i){ f[i-1]=val[i]*i; } return f; } FPS integral_(){ FPS f(val.size()+1); for(size_t i=0;i<val.size();++i){ f[i+1]=val[i]/(i+1); } return f; } FPS inv_(int mx=-1){ if(mx==-1){ mx=val.size(); } if(val[0]==0){ assert(0); } FPS g({mint(1)/val[0]}); int now=1; while(now<mx){ now<<=1; FPS t=(*this); t.resize(now); t*=g; t=-t+mint(2); g*=t; g.resize(now); } g.resize(mx); return g; } FPS exp_(int mx=-1){ if(mx==-1){ mx=val.size(); } if(val[0]!=0){ assert(0); } FPS g(mint(1)); int now=1; while(now<mx){ now<<=1; FPS t=(*this); t.resize(now); g*=t-g.log_(now)+mint(1); g.resize(now); } g.resize(mx); return g; } FPS log_(int mx=-1){ if(mx==-1){ mx=val.size(); } if(val[0]!=1){ assert(0); } auto f=(*this); f.resize(mx); return (f.diff_()/f).integral_().resize_(mx); } FPS pow_(i64 k,int mx=-1){ if(mx==-1){ mx=val.size(); } i64 t=0; for(auto v:val){ if(v==0){ t++; } else{ break; } } auto f=(*this)>>t; if(f[0]==0){ f={0},f.resize(mx); return f; } mint c=f[0]; f/=c; (f.log(mx)*=mint(k)).exp(mx)*=c.pow(k); if(t*k<=mx){ f<<=t*k; f.resize(mx); return f; } else{ f={0},f.resize(mx); return f; } } FPS& diff(){ return (*this)=diff_(); } FPS& integral(){ return (*this)=integral_(); } FPS& inv(int mx=-1){ return (*this)=inv_(mx); } FPS& exp(int mx=-1){ return (*this)=exp_(mx); } FPS& log(int mx=-1){ return (*this)=log_(mx); } FPS& pow(i64 k,int mx=-1){ return (*this)=pow_(k,mx); } void taylor_shift(mint c){ cmb<mint> C(val.size()); vector<mint> g(val.size()); mint now=1; for(size_t i=0;i<val.size();++i){ val[i]*=C.dat[i]; g[i]=now*C.idat[i]; now*=c; } reverse(val.begin(),val.end()); g=ntt(val,g); g.resize(val.size()); reverse(g.begin(),g.end()); for(size_t i=0;i<val.size();++i){ g[i]*=C.idat[i]; } val=g; } }; template<u64 mod> FPS<mod> product(vector<FPS<mod>> a){ int siz=1; while(siz<int(a.size())){ siz<<=1; } vector<FPS<mod>> res(siz*2-1,{1}); for(int i=0;i<int(a.size());++i){ res[i+siz-1]=a[i]; } for(int i=siz-2;i>=0;--i){ res[i]=res[2*i+1]*res[2*i+2]; } return res[0]; } template<u64 mod> FPS<mod> inv_sum(int M,vector<FPS<mod>> f,vector<FPS<mod>> g){ int siz=1; while(siz<int(f.size())){ siz<<=1; } vector<FPS<mod>> mol(siz*2-1),den(siz*2-1,{1}); for(size_t i=0;i<f.size();++i){ mol[i+siz-1]=f[i]; den[i+siz-1]=g[i]; } for(int i=siz-2;i>=0;--i){ den[i]=den[2*i+1]*den[2*i+2]; mol[i]=mol[2*i+1]*den[2*i+2]+mol[2*i+2]*den[2*i+1]; } mol[0]*=den[0].inv(M+1); return mol[0].resize_(M+1); } int main(){ constexpr int mod=998244353; using mint=modint<mod>; cmb<mint> Cb; int N,M; cin>>N>>M; vector<mint> A(N); scn(A); vector<FPS<mod>> f(N),g(N); for(int i=0;i<N;++i){ f[i]={1},g[i]={1,-A[i]}; } auto v=inv_sum(M,f,g); for(int i=1;i<=M;++i){ cout<<v[i]<<" \n"[i==M]; } }