結果

問題 No.1861 Required Number
ユーザー MtSakaMtSaka
提出日時 2021-12-27 03:00:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,500 ms
コード長 755 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 207,700 KB
実行使用メモリ 6,800 KB
最終ジャッジ日時 2023-09-26 02:55:40
合計ジャッジ時間 9,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 69 ms
6,660 KB
testcase_04 AC 70 ms
6,800 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 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,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 24 ms
4,384 KB
testcase_25 AC 53 ms
6,116 KB
testcase_26 AC 15 ms
4,380 KB
testcase_27 AC 23 ms
4,744 KB
testcase_28 AC 27 ms
4,544 KB
testcase_29 AC 17 ms
4,796 KB
testcase_30 AC 11 ms
4,392 KB
testcase_31 AC 58 ms
5,976 KB
testcase_32 AC 9 ms
4,384 KB
testcase_33 AC 38 ms
5,336 KB
testcase_34 AC 43 ms
5,712 KB
testcase_35 AC 46 ms
6,112 KB
testcase_36 AC 20 ms
4,728 KB
testcase_37 AC 25 ms
5,092 KB
testcase_38 AC 48 ms
5,584 KB
testcase_39 AC 31 ms
4,788 KB
testcase_40 AC 56 ms
6,664 KB
testcase_41 AC 54 ms
6,280 KB
testcase_42 AC 44 ms
5,724 KB
testcase_43 AC 27 ms
4,752 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<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<vector<bool>>dpl(N+1,vector<bool>(K+1,false)),dpr(N+2,vector<bool>(K+1,false));
  dpl[0][0]=dpr[N+1][0]=true;
  for(int i=0;i<N;i++){
    dpl[i+1]=dpl[i];
    for(int j=0;j<=K-A[i];j++){
      if(dpl[i][j])dpl[i+1][j+A[i]]=true;
    }
  }
  for(int i=N-1;i>=0;i--){
    dpr[i+1]=dpr[i+2];
    for(int j=0;j<=K-A[i];j++){
      if(dpr[i+2][j])dpr[i+1][j+A[i]]=true;
    }
  }
  if(!dpl[N][K]){
    cout<<-1<<endl;
    return 0;
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    bool flag=true;
    for(int j=0;j<=K;j++){
      if(dpl[i-1][j]&&dpr[i+1][K-j])flag=false;
    }
    if(flag)ans++;
  }
  cout<<ans<<endl;
}
0