結果

問題 No.2272 多項式乗算 mod 258280327
ユーザー shobonvipshobonvip
提出日時 2023-04-14 22:18:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 588 ms / 2,000 ms
コード長 2,378 bytes
コンパイル時間 5,160 ms
コンパイル使用メモリ 266,420 KB
実行使用メモリ 26,192 KB
最終ジャッジ日時 2024-04-18 19:47:22
合計ジャッジ時間 9,280 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 8 ms
5,376 KB
testcase_25 AC 25 ms
5,376 KB
testcase_26 AC 26 ms
5,376 KB
testcase_27 AC 55 ms
6,548 KB
testcase_28 AC 54 ms
6,504 KB
testcase_29 AC 282 ms
14,736 KB
testcase_30 AC 571 ms
26,184 KB
testcase_31 AC 559 ms
26,192 KB
testcase_32 AC 588 ms
26,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint mint;
typedef long long ll;

mint Garner(vector<long long> m,vector<long long> r){
	int n = m.size();
	vector<long long> t(n);
	for(int i=0; i<n; i++){
		long long cur = 0LL;
		long long cm = 1LL;
		for(int j=0; j<i; j++){
			cur += t[j] * cm;
			cur %= m[i];
			cm *= m[j];
			cm %= m[i];
		}
		cur = r[i] - cur;
		cur %= m[i];
		if(cur<0)cur += m[i];
		if(i==1)cur *= 416537774;
		if(i==2)cur *= 429847628;
		
		//cur *= inv_mod(cm,m[i]);
		
		cur %= m[i];
		t[i] = cur;
	}
	
	mint ret = 0;
	mint cm = 1;
	for(int i=0; i<n; i++){
		ret += cm * t[i];
		cm *= m[i];
	}
	return ret;
	
}

template <class T>
vector<T> convolution_mint(vector<T> a,vector<T> b){
	
	static constexpr unsigned long long M0 = 998244353;
	static constexpr unsigned long long M1 = 754974721;
	static constexpr unsigned long long M2 = 469762049;
	
	vector<long long> aa(a.size()),bb(b.size());
	for(int i=0; i<a.size(); i++)aa[i] = a[i].val();
	for(int i=0; i<b.size(); i++)bb[i] = b[i].val();
	
	auto c0 = convolution<M0>(aa,bb);
	auto c1 = convolution<M1>(aa,bb);
	auto c2 = convolution<M2>(aa,bb);
	
	vector<mint> ret(c0.size());
	vector<long long> m = {M0,M1,M2};
	for(int i=0; i<c0.size(); i++){
		vector<long long> r = {c0[i],c1[i],c2[i]};
		vector<long long> t(3);
		for(int j=0; j<3; j++){
			long long cur = 0LL;
			long long cm = 1LL;
			for(int k=0; k<j; k++){
				cur += t[k] * cm;
				cur %= m[j];
				cm *= m[k];
				cm %= m[j];
			}
			cur = r[j] - cur;
			cur %= m[j];
			if(cur<0)cur += m[j];
			if(j==1)cur *= 416537774;
			if(j==2)cur *= 429847628;
			cur %= m[j];
			t[j] = cur;
		}
		
		mint cm = 1;
		for(int j=0; j<3; j++){
			ret[i] += cm * t[j];
			cm *= m[j];
		}
	}
	
	return ret;
}


int main(){
	modint::set_mod(258280327);
	bool mode = false;
	int n; cin >> n;
	vector<mint> a(n+1);
	for (int i=0; i<n+1; i++){
		ll x; cin >> x;
		a[i] = x;
		if (n==0 && x==(ll)0) mode = true;
	}
	int m; cin >> m;
	vector<mint> b(m+1);
	for (int i=0; i<m+1; i++){
		ll x; cin >> x;
		b[i] = x;
		if (m==0 && x==(ll)0) mode = true;
	}
	if (mode){
		cout << 0 << "\n";
		cout << 0 << "\n";
	}else{
		vector<mint> c = convolution_mint<mint>(a, b);
		cout << n+m << endl;
		for (int i=0; i<n+m+1; i++){
			cout << c[i].val();
			if (i==n+m) cout << "\n";
			else cout << " ";
		}
	}
}
0