結果

問題 No.2215 Slide Subset Sum
ユーザー 👑 kmjpkmjp
提出日時 2023-02-10 22:47:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 791 ms / 3,000 ms
コード長 1,581 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 201,748 KB
実行使用メモリ 292,748 KB
最終ジャッジ日時 2023-09-21 23:56:27
合計ジャッジ時間 23,071 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 487 ms
166,016 KB
testcase_01 AC 264 ms
5,532 KB
testcase_02 AC 784 ms
166,028 KB
testcase_03 AC 789 ms
166,028 KB
testcase_04 AC 782 ms
166,012 KB
testcase_05 AC 2 ms
7,628 KB
testcase_06 AC 3 ms
7,496 KB
testcase_07 AC 2 ms
5,428 KB
testcase_08 AC 2 ms
7,668 KB
testcase_09 AC 3 ms
7,476 KB
testcase_10 AC 2 ms
5,480 KB
testcase_11 AC 2 ms
5,412 KB
testcase_12 AC 3 ms
7,668 KB
testcase_13 AC 3 ms
7,820 KB
testcase_14 AC 3 ms
7,636 KB
testcase_15 AC 2 ms
7,604 KB
testcase_16 AC 5 ms
7,960 KB
testcase_17 AC 765 ms
222,752 KB
testcase_18 AC 724 ms
190,972 KB
testcase_19 AC 780 ms
166,932 KB
testcase_20 AC 615 ms
166,280 KB
testcase_21 AC 754 ms
167,284 KB
testcase_22 AC 619 ms
178,576 KB
testcase_23 AC 791 ms
290,028 KB
testcase_24 AC 783 ms
292,748 KB
testcase_25 AC 742 ms
260,144 KB
testcase_26 AC 627 ms
179,172 KB
testcase_27 AC 43 ms
18,836 KB
testcase_28 AC 68 ms
52,016 KB
testcase_29 AC 56 ms
22,484 KB
testcase_30 AC 402 ms
99,596 KB
testcase_31 AC 291 ms
125,652 KB
testcase_32 AC 66 ms
22,316 KB
testcase_33 AC 530 ms
141,124 KB
testcase_34 AC 490 ms
190,344 KB
testcase_35 AC 144 ms
58,552 KB
testcase_36 AC 144 ms
55,784 KB
testcase_37 AC 431 ms
166,084 KB
testcase_38 AC 180 ms
166,072 KB
testcase_39 AC 265 ms
5,736 KB
testcase_40 AC 262 ms
5,540 KB
testcase_41 AC 2 ms
5,408 KB
testcase_42 AC 599 ms
166,028 KB
testcase_43 AC 763 ms
166,012 KB
testcase_44 AC 754 ms
166,084 KB
testcase_45 AC 713 ms
244,452 KB
testcase_46 AC 716 ms
244,392 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,K;
int A[402020];

int L[404040][101];
int R[404040][101];

const ll mo=998244353;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	FOR(i,N) cin>>A[i];
	
	if(M==1) {
		FOR(i,N) {
			cout<<(A[i]==0)<<endl;
		}
		return;
	}
	
	int ON=N;
	N=(N+M-1)/M*M;
	FOR(i,N) {
		if(i%M==0) {
			ZERO(L[i]);
			L[i][0]=1;
		}
		FOR(j,K) {
			(L[i+1][j]+=L[i][j])%=mo;;
			(L[i+1][(j+A[i])%K]+=L[i][j])%=mo;
		}
	}
	for(i=N;i>=1;i--) {
		if(i%M==0) {
			ZERO(R[i]);
			R[i][0]=1;
		}
		FOR(j,K) {
			(R[i-1][j]+=R[i][j])%=mo;;
			(R[i-1][(j+A[i-1])%K]+=R[i][j])%=mo;
		}
	}
	for(i=0;i+M<=ON;i++) {
		ll ret=mo-1;
		if(i%M==0) {
			FOR(j,K) ret+=1LL*L[i+1][j]*R[i+1][(K-j)%K]%mo;
		}
		else {
			FOR(j,K) ret+=1LL*R[i][j]*L[i+M][(K-j)%K]%mo;
		}
		cout<<ret%mo<<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