結果

問題 No.931 Multiplicative Convolution
ユーザー 👑 kmjpkmjp
提出日時 2019-11-23 01:20:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,358 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 178,148 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2023-08-01 15:07:30
合計ジャッジ時間 5,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,292 KB
testcase_01 AC 5 ms
7,296 KB
testcase_02 RE -
testcase_03 AC 4 ms
7,480 KB
testcase_04 AC 5 ms
7,208 KB
testcase_05 AC 4 ms
7,216 KB
testcase_06 AC 6 ms
7,296 KB
testcase_07 AC 28 ms
8,032 KB
testcase_08 AC 248 ms
15,312 KB
testcase_09 AC 62 ms
11,312 KB
testcase_10 AC 220 ms
15,980 KB
testcase_11 AC 220 ms
15,896 KB
testcase_12 AC 116 ms
11,216 KB
testcase_13 AC 756 ms
16,232 KB
testcase_14 AC 364 ms
16,384 KB
testcase_15 AC 252 ms
15,456 KB
testcase_16 AC 243 ms
15,244 KB
権限があれば一括ダウンロードができます

ソースコード

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 P;
int rt;
ll A[101001];
ll B[101001];
ll R[101001];

const ll mo=998244353;

ll get_root(ll p) {
	// pの原子根を求める
	for(int i=2;i<p;i++) {
		set<int> S;
		int x=1,j;
		while(1) {
			if(S.size()==p-1) return i;
			if(S.count(x)) break;
			S.insert(x);
			x=x*i%p;
		}
		
	}
	assert(0);
}

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);
}



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>P;
	rt=get_root(P);
	FOR(i,P-1) cin>>A[i+1];
	FOR(i,P-1) cin>>B[i+1];
	
	vector<ll> X(1<<17),Y(1<<17);
	ll v=1;
	FOR(i,P-1) {
		X[i]=A[v];
		Y[i]=B[v];
		v=v*rt%P;
	}
	auto Z=MultPoly(X,Y,true);
	v=1;
	FOR(i,Z.size()) {
		R[v]+=Z[i];
		v=v*rt%P;
	}
	
	FOR(i,P-1) cout<<R[i+1]%mo<<" ";
	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