結果

問題 No.2164 Equal Balls
ユーザー 👑 kmjpkmjp
提出日時 2022-12-17 01:11:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,212 ms / 5,000 ms
コード長 2,915 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 214,592 KB
実行使用メモリ 21,500 KB
最終ジャッジ日時 2024-04-27 23:43:36
合計ジャッジ時間 28,558 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,624 KB
testcase_01 AC 5 ms
10,624 KB
testcase_02 AC 8 ms
10,752 KB
testcase_03 AC 6 ms
10,624 KB
testcase_04 AC 6 ms
10,752 KB
testcase_05 AC 7 ms
10,624 KB
testcase_06 AC 7 ms
10,752 KB
testcase_07 AC 7 ms
10,880 KB
testcase_08 AC 97 ms
13,296 KB
testcase_09 AC 83 ms
12,992 KB
testcase_10 AC 41 ms
11,904 KB
testcase_11 AC 210 ms
15,452 KB
testcase_12 AC 99 ms
13,240 KB
testcase_13 AC 64 ms
12,288 KB
testcase_14 AC 86 ms
13,448 KB
testcase_15 AC 206 ms
16,128 KB
testcase_16 AC 93 ms
13,328 KB
testcase_17 AC 23 ms
10,880 KB
testcase_18 AC 131 ms
14,312 KB
testcase_19 AC 226 ms
16,064 KB
testcase_20 AC 106 ms
13,336 KB
testcase_21 AC 19 ms
11,008 KB
testcase_22 AC 16 ms
11,008 KB
testcase_23 AC 429 ms
12,844 KB
testcase_24 AC 370 ms
17,072 KB
testcase_25 AC 371 ms
11,776 KB
testcase_26 AC 259 ms
16,740 KB
testcase_27 AC 436 ms
16,476 KB
testcase_28 AC 448 ms
16,424 KB
testcase_29 AC 166 ms
12,368 KB
testcase_30 AC 379 ms
14,712 KB
testcase_31 AC 518 ms
12,520 KB
testcase_32 AC 459 ms
17,736 KB
testcase_33 AC 271 ms
11,648 KB
testcase_34 AC 365 ms
12,860 KB
testcase_35 AC 75 ms
10,880 KB
testcase_36 AC 758 ms
17,212 KB
testcase_37 AC 584 ms
12,416 KB
testcase_38 AC 1,196 ms
21,368 KB
testcase_39 AC 1,204 ms
21,348 KB
testcase_40 AC 1,200 ms
21,368 KB
testcase_41 AC 1,206 ms
21,496 KB
testcase_42 AC 1,199 ms
21,500 KB
testcase_43 AC 1,204 ms
21,500 KB
testcase_44 AC 1,197 ms
21,496 KB
testcase_45 AC 1,202 ms
21,496 KB
testcase_46 AC 1,212 ms
21,500 KB
testcase_47 AC 1,210 ms
21,496 KB
testcase_48 AC 1,196 ms
21,496 KB
testcase_49 AC 631 ms
12,160 KB
testcase_50 AC 632 ms
12,160 KB
testcase_51 AC 635 ms
12,288 KB
testcase_52 AC 633 ms
12,160 KB
testcase_53 AC 632 ms
12,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[202020],B[202020];
ll dp[303][603];
ll dp2[603];
const ll mo=998244353;

ll dp3[303][303*303*2];

ll modpow(ll a, ll n = mo-2) {
	ll r=1; a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

template <class T> using vec=vector<T>; //using vec=valarray<T>;

template<class T> vec<T> fft(vec<T> v, bool rev=false) {
	int n=v.size(),i,j,m;
	for(int m=n; m>=2; m/=2) {
		T wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			T w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				T t1=v[j1],t2=v[j2];
				v[j1]=t1+t2;
				v[j2]=ll(t1+mo-t2)*w%mo;
				while(v[j1]>=mo) v[j1]-=mo;
				w=(ll)w*wn%mo;
			}
		}
	}
	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]);
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=(ll)v[i]*rv%mo;
	}
	return v;
}

template<class T> vec<T> MultPoly(vec<T> P,vec<T> 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;
		
		if(s<=16) { //fastpath
			vec<T> R(s*2);
			for(int x=0;x<=pi;x++) for(int y=0;y<=qi;y++) (R[x+y]+=P[x]*Q[y])%=mo;
			return R;
		}
		vec<T> P2(s*2),Q2(s*2);
		FOR(i,pi+1) P2[i]=P[i];
		FOR(i,qi+1) Q2[i]=Q[i];
		swap(P,P2),swap(Q,Q2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=(ll)P[i]*Q[i]%mo;
	return fft(P,true);
}

ll comb(int P_,int Q_) {
	static const int N_=1020;
	static ll C_[N_][N_];
	
	if(C_[0][0]==0) {
		int i,j;
		FOR(i,N_) C_[i][0]=C_[i][i]=1;
		for(i=1;i<N_;i++) for(j=1;j<i;j++) C_[i][j]=(C_[i-1][j-1]+C_[i-1][j])%mo;
	}
	if(P_<0 || P_>N_ || Q_<0 || Q_>P_) return 0;
	return C_[P_][Q_];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>A[i];
	FOR(i,N) cin>>B[i];
	queue<vec<ll>> Q;
	FOR(i,M) {
		vector<ll> D(601,1);
		for(k=i;k<N;k+=M) {
			for(x=-300;x<=300;x++) (D[300+x]*=comb(A[k]+B[k],B[k]+x))%=mo;
		}
		Q.push(D);
	}
	while(Q.size()>1) {
		auto a=Q.front();
		Q.pop();
		Q.push(MultPoly(a,Q.front(),1));
		Q.pop();
	}
	vec<ll> V=Q.front();
	cout<<V[300*M]<<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