結果

問題 No.1861 Required Number
ユーザー 沙耶花沙耶花
提出日時 2022-03-04 23:33:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,500 ms
コード長 698 bytes
コンパイル時間 5,224 ms
コンパイル使用メモリ 263,836 KB
実行使用メモリ 247,328 KB
最終ジャッジ日時 2023-09-26 03:57:56
合計ジャッジ時間 13,340 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 167 ms
247,280 KB
testcase_04 AC 169 ms
247,224 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 7 ms
7,592 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,680 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,460 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
5,272 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,460 KB
testcase_19 AC 5 ms
5,488 KB
testcase_20 AC 3 ms
4,640 KB
testcase_21 AC 4 ms
4,640 KB
testcase_22 AC 5 ms
5,488 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 96 ms
112,376 KB
testcase_25 AC 199 ms
232,208 KB
testcase_26 AC 116 ms
136,616 KB
testcase_27 AC 176 ms
210,408 KB
testcase_28 AC 145 ms
172,424 KB
testcase_29 AC 187 ms
225,272 KB
testcase_30 AC 195 ms
234,480 KB
testcase_31 AC 192 ms
226,044 KB
testcase_32 AC 190 ms
227,480 KB
testcase_33 AC 191 ms
226,344 KB
testcase_34 AC 188 ms
224,828 KB
testcase_35 AC 208 ms
244,164 KB
testcase_36 AC 190 ms
226,684 KB
testcase_37 AC 204 ms
243,708 KB
testcase_38 AC 187 ms
224,308 KB
testcase_39 AC 186 ms
223,544 KB
testcase_40 AC 207 ms
247,324 KB
testcase_41 AC 196 ms
232,928 KB
testcase_42 AC 208 ms
247,328 KB
testcase_43 AC 200 ms
236,524 KB
testcase_44 AC 2 ms
4,376 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000


int main(){
	
	int n,k;
	cin>>n>>k;
	
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	vector<bitset<100001>> pre(n+1),suf(n+1);
	pre[0][0] = 1;
	rep(i,n){
		pre[i+1] = pre[i];
		pre[i+1] |= pre[i]<<a[i];
	}
	
	suf[n][k] = 1;
	for(int i=n-1;i>=0;i--){
		suf[i] = suf[i+1];
		suf[i] |= suf[i+1]>>a[i];
	}
	if(pre.back()[k]==0){
		cout<<-1<<endl;
		return 0;
	}
	int ans = 0;
	rep(i,n){
		pre[i] &= suf[i+1];
		if(!pre[i].any()){
			//cout<<i<<endl;
			ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}
0