結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 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 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 25 ms
5,376 KB
testcase_26 AC 25 ms
5,376 KB
testcase_27 AC 54 ms
6,420 KB
testcase_28 AC 53 ms
6,508 KB
testcase_29 AC 277 ms
14,616 KB
testcase_30 AC 566 ms
26,124 KB
testcase_31 AC 544 ms
26,116 KB
testcase_32 AC 569 ms
26,036 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);
	int n; cin >> n;
	vector<mint> a(n+1);
	for (int i=0; i<n+1; i++){
		ll x; cin >> x;
		a[i] = x;
	}
	int m; cin >> m;
	vector<mint> b(m+1);
	for (int i=0; i<m+1; i++){
		ll x; cin >> x;
		b[i] = x;
	}
	vector<mint> c = convolution_mint<mint>(a, b);
	int ind = 0;
	for (int i=0; i<n+m+1; i++){
		if (c[i].val() != 0){
			ind = i;
		}
	}

	cout << ind << "\n";
	for (int i=0; i<ind+1; i++){
		cout << c[i].val();
		if (i==ind) cout << "\n";
		else cout << " ";
	}
}
0