結果

問題 No.1145 Sums of Powers
ユーザー 👑 kmjpkmjp
提出日時 2020-08-03 18:59:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,029 bytes
コンパイル時間 3,197 ms
コンパイル使用メモリ 218,888 KB
実行使用メモリ 24,912 KB
最終ジャッジ日時 2023-10-11 14:26:13
合計ジャッジ時間 12,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 17 ms
4,348 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,M;
int A[101010];

const int mo=998244353;
ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
vector<ll> fft(vector<ll> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		ll wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			ll w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				ll t1=v[j1],t2=w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=v[i]*rv%mo;
	}
	return v;
}

vector<ll> MultPoly(vector<ll> P,vector<ll> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=P[i]*Q[i]%mo;
	return fft(P,true);
}

pair<vector<ll>,vector<ll>> add(pair<vector<ll>,vector<ll>> a, pair<vector<ll>,vector<ll>> b) {
	vector<ll> c=MultPoly(a.first,b.second,true);
	vector<ll> d=MultPoly(b.first,a.second,true);
	vector<ll> e=MultPoly(a.second,b.second,true);
	if(c.size()<d.size()) swap(c,d);
	int i;
	FOR(i,d.size()) {
		c[i]+=d[i];
		if(c[i]>=mo) c[i]-=mo;
	}
	
	return {c,e};
}

vector<ll> inverse(vector<ll> a) {
	assert(a[0]>0);
	vector<ll> b={modpow(a[0])};
	while(b.size()<a.size()) {
		vector<ll> c(a.begin(),a.begin()+min(a.size(),2*b.size()));
		vector<ll> d=MultPoly(b,b,true);
		c = MultPoly(c,d,true);
		b.resize(2*b.size());
		int i;
		for(i=b.size()/2;i<b.size();i++) b[i]=(mo-c[i])%mo;
	}
	b.resize(a.size());
	return b;
	
}


void solve() {
	int i,j,k,l,x,y; string s;
	
	cin>>N>>M;
	queue<pair<vector<ll>,vector<ll>>> Q;
	FOR(i,N) {
		cin>>A[i];
		vector<ll> a={1};
		vector<ll> b={1,(mo-A[i])%mo};
		Q.push({a,b});
	}
	while(Q.size()>=2) {
		pair<vector<ll>,vector<ll>> a=Q.front();
		Q.pop();
		pair<vector<ll>,vector<ll>> b=Q.front();
		Q.pop();
		Q.push(add(a,b));
	}
	
	pair<vector<ll>,vector<ll>> a=Q.front();
	vector<ll> p=a.first;
	a.second.resize(M+1);
	vector<ll> q=inverse(a.second);
	vector<ll> r=MultPoly(p,q,true);
	
	for(i=1;i<=M;i++) cout<<r[i]<<" ";
	cout<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0