結果

問題 No.1861 Required Number
ユーザー 沙耶花沙耶花
提出日時 2022-03-04 21:26:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,500 ms
コード長 890 bytes
コンパイル時間 4,367 ms
コンパイル使用メモリ 263,984 KB
実行使用メモリ 6,792 KB
最終ジャッジ日時 2023-09-26 03:11:00
合計ジャッジ時間 11,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 80 ms
6,728 KB
testcase_04 AC 82 ms
6,792 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 26 ms
4,416 KB
testcase_25 AC 61 ms
6,324 KB
testcase_26 AC 15 ms
4,376 KB
testcase_27 AC 25 ms
5,008 KB
testcase_28 AC 30 ms
4,680 KB
testcase_29 AC 19 ms
4,680 KB
testcase_30 AC 9 ms
4,420 KB
testcase_31 AC 64 ms
6,212 KB
testcase_32 AC 9 ms
4,480 KB
testcase_33 AC 44 ms
5,736 KB
testcase_34 AC 51 ms
5,812 KB
testcase_35 AC 53 ms
6,116 KB
testcase_36 AC 20 ms
4,752 KB
testcase_37 AC 28 ms
5,324 KB
testcase_38 AC 54 ms
5,684 KB
testcase_39 AC 33 ms
5,060 KB
testcase_40 AC 64 ms
6,460 KB
testcase_41 AC 60 ms
6,264 KB
testcase_42 AC 49 ms
5,668 KB
testcase_43 AC 30 ms
5,140 KB
testcase_44 AC 2 ms
4,380 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 1000000003

vector<vector<bool>> get(vector<int> a,int K){
	int n = a.size();
	vector dp(n+1,vector<bool>(K+1,false));
	dp[0][0] = true;
	rep(i,n){
		rep(j,K+1){
			if(dp[i][j]){
				dp[i+1][j] = true;
				if(j+a[i]<=K)dp[i+1][j+a[i]] = true;
			}
		}
	}
	return dp;
}

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> a(N);
	rep(i,N){
		cin>>a[i];
	}
	
	auto x = get(a,K);
	reverse(a.begin(),a.end());
	auto y = get(a,K);
	if(x.back().back()==false){
		cout<<-1<<endl;
		return 0;
	}
	int ans = 0;
	rep(i,N){
		bool f = false;
		rep(j,K+1){
			if(x[i][j]==false)continue;
			if(y[N-1-i][K-j]==false)continue;
			f = true;
			break;
		}
		if(!f)ans++;
		
		
	}
	cout<<ans<<endl;
	
	return 0;
}
0