結果

問題 No.2164 Equal Balls
ユーザー 👑 kmjpkmjp
提出日時 2022-12-17 01:11:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,069 ms / 5,000 ms
コード長 2,915 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 212,048 KB
実行使用メモリ 24,464 KB
最終ジャッジ日時 2023-08-10 06:25:55
合計ジャッジ時間 27,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,024 KB
testcase_01 AC 5 ms
15,036 KB
testcase_02 AC 6 ms
15,088 KB
testcase_03 AC 5 ms
15,072 KB
testcase_04 AC 6 ms
15,088 KB
testcase_05 AC 7 ms
15,100 KB
testcase_06 AC 6 ms
15,120 KB
testcase_07 AC 7 ms
15,076 KB
testcase_08 AC 89 ms
17,512 KB
testcase_09 AC 75 ms
17,364 KB
testcase_10 AC 38 ms
16,144 KB
testcase_11 AC 195 ms
19,684 KB
testcase_12 AC 93 ms
17,372 KB
testcase_13 AC 59 ms
16,480 KB
testcase_14 AC 81 ms
17,460 KB
testcase_15 AC 191 ms
20,440 KB
testcase_16 AC 85 ms
17,508 KB
testcase_17 AC 22 ms
15,444 KB
testcase_18 AC 123 ms
18,548 KB
testcase_19 AC 212 ms
20,348 KB
testcase_20 AC 100 ms
17,588 KB
testcase_21 AC 17 ms
15,320 KB
testcase_22 AC 15 ms
15,240 KB
testcase_23 AC 355 ms
16,000 KB
testcase_24 AC 328 ms
20,892 KB
testcase_25 AC 311 ms
15,240 KB
testcase_26 AC 235 ms
20,832 KB
testcase_27 AC 383 ms
20,324 KB
testcase_28 AC 384 ms
20,008 KB
testcase_29 AC 139 ms
16,396 KB
testcase_30 AC 329 ms
18,664 KB
testcase_31 AC 416 ms
15,584 KB
testcase_32 AC 414 ms
21,372 KB
testcase_33 AC 224 ms
15,432 KB
testcase_34 AC 306 ms
16,132 KB
testcase_35 AC 62 ms
15,148 KB
testcase_36 AC 639 ms
20,056 KB
testcase_37 AC 490 ms
15,568 KB
testcase_38 AC 1,052 ms
24,200 KB
testcase_39 AC 1,047 ms
24,176 KB
testcase_40 AC 1,047 ms
24,220 KB
testcase_41 AC 1,055 ms
24,104 KB
testcase_42 AC 1,065 ms
24,104 KB
testcase_43 AC 1,061 ms
24,104 KB
testcase_44 AC 1,069 ms
24,152 KB
testcase_45 AC 1,065 ms
24,220 KB
testcase_46 AC 1,059 ms
24,464 KB
testcase_47 AC 1,038 ms
24,152 KB
testcase_48 AC 1,042 ms
24,180 KB
testcase_49 AC 535 ms
15,008 KB
testcase_50 AC 522 ms
15,024 KB
testcase_51 AC 526 ms
15,148 KB
testcase_52 AC 524 ms
15,136 KB
testcase_53 AC 522 ms
15,088 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