結果

問題 No.1963 Subset Mex
ユーザー 1kri1kri
提出日時 2022-07-14 10:29:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 4,000 ms
コード長 1,361 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 64,296 KB
実行使用メモリ 13,488 KB
最終ジャッジ日時 2023-09-08 00:15:53
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,264 KB
testcase_01 AC 5 ms
13,312 KB
testcase_02 AC 6 ms
13,280 KB
testcase_03 AC 6 ms
13,276 KB
testcase_04 AC 6 ms
13,460 KB
testcase_05 AC 6 ms
13,348 KB
testcase_06 AC 7 ms
13,200 KB
testcase_07 AC 6 ms
13,264 KB
testcase_08 AC 6 ms
13,328 KB
testcase_09 AC 6 ms
13,324 KB
testcase_10 AC 6 ms
13,260 KB
testcase_11 AC 6 ms
13,440 KB
testcase_12 AC 12 ms
13,268 KB
testcase_13 AC 13 ms
13,276 KB
testcase_14 AC 14 ms
13,324 KB
testcase_15 AC 15 ms
13,200 KB
testcase_16 AC 17 ms
13,184 KB
testcase_17 AC 20 ms
13,488 KB
testcase_18 AC 31 ms
13,212 KB
testcase_19 AC 76 ms
13,180 KB
testcase_20 AC 130 ms
13,280 KB
testcase_21 AC 262 ms
13,268 KB
testcase_22 AC 303 ms
13,444 KB
testcase_23 AC 248 ms
13,160 KB
testcase_24 AC 181 ms
13,352 KB
testcase_25 AC 152 ms
13,204 KB
testcase_26 AC 19 ms
13,140 KB
testcase_27 AC 32 ms
13,280 KB
testcase_28 AC 68 ms
13,304 KB
testcase_29 AC 90 ms
13,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#define mod 998244353
using namespace std;
int t,n,m,x,cnt[115],sum[115],f[115][105][105],ok[115][105][105];
void upd(int &x,int y){
	x+=y;
	if (x>=mod)x-=mod;
	return;
}
int check(int now,int rest,int d){
	if (d>n)return 0;
	if (now==0){
		if (d<=rest+cnt[now])return 1;
		return 0;
	}
	if (ok[now][rest][d]!=-1)return ok[now][rest][d];
	if (cnt[now]>=d)return ok[now][rest][d]=check(now-1,rest+cnt[now]-d,d);
	return ok[now][rest][d]=check(now-1,rest,d+(d-cnt[now]));
}
int dfs(int now,int rest,int d){
	if (d>n)return 0;
	if (f[now][rest][d]!=-1)return f[now][rest][d];
	int ans=0;
	for (int i=0;i<=n;i++){
		int _rest=rest,_d=d;
		if (cnt[now]>=i+d)_rest+=cnt[now]-(i+d);
		else _d+=(i+d)-cnt[now];
		if (now>0)upd(ans,dfs(now-1,_rest,_d));
		if (i>0){
			if (now==0){
				if (i+d<=rest+cnt[now])upd(ans,1);
			}
			else{
				if (_d>0){
					if (check(now-1,_rest,_d))upd(ans,1);
				}
				else if ((_rest==0&&sum[now-1]==0)||check(now-1,_rest+1,1))upd(ans,1);
			}
		}
	}
	return f[now][rest][d]=ans;
}
int main(){
    t=1;
	while(t--){
		cin>>n;
		memset(cnt,0,sizeof(cnt));
		for (int i=1;i<=n;i++){
			cin>>x;
			cnt[x]++;
		}
		m=114;
		sum[0]=cnt[0];
		for (int i=1;i<=m;i++)sum[i]=cnt[i]+sum[i-1];
		memset(f,-1,sizeof(f));
		memset(ok,-1,sizeof(ok));
		cout<<dfs(m,0,0)<<endl;
	}
	return 0;
}
0