結果

問題 No.1861 Required Number
ユーザー umezoumezo
提出日時 2022-03-04 22:30:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 201,112 KB
実行使用メモリ 82,440 KB
最終ジャッジ日時 2023-09-26 03:44:46
合計ジャッジ時間 10,320 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,612 KB
testcase_01 AC 2 ms
5,404 KB
testcase_02 AC 2 ms
5,488 KB
testcase_03 AC 119 ms
82,412 KB
testcase_04 AC 119 ms
82,416 KB
testcase_05 AC 2 ms
5,524 KB
testcase_06 AC 2 ms
5,432 KB
testcase_07 WA -
testcase_08 AC 3 ms
6,404 KB
testcase_09 AC 2 ms
5,596 KB
testcase_10 AC 2 ms
5,680 KB
testcase_11 AC 2 ms
5,576 KB
testcase_12 AC 2 ms
5,496 KB
testcase_13 AC 3 ms
5,720 KB
testcase_14 AC 2 ms
5,484 KB
testcase_15 AC 2 ms
5,876 KB
testcase_16 AC 2 ms
5,472 KB
testcase_17 AC 2 ms
5,496 KB
testcase_18 WA -
testcase_19 AC 3 ms
5,860 KB
testcase_20 AC 2 ms
5,824 KB
testcase_21 AC 2 ms
5,688 KB
testcase_22 AC 3 ms
5,836 KB
testcase_23 AC 2 ms
5,496 KB
testcase_24 AC 52 ms
40,112 KB
testcase_25 AC 114 ms
79,912 KB
testcase_26 AC 51 ms
48,164 KB
testcase_27 AC 83 ms
72,300 KB
testcase_28 AC 73 ms
60,008 KB
testcase_29 AC 83 ms
76,744 KB
testcase_30 AC 79 ms
80,248 KB
testcase_31 AC 114 ms
76,872 KB
testcase_32 AC 79 ms
77,120 KB
testcase_33 AC 103 ms
76,904 KB
testcase_34 AC 107 ms
76,672 KB
testcase_35 AC 117 ms
81,828 KB
testcase_36 AC 87 ms
76,948 KB
testcase_37 AC 95 ms
81,876 KB
testcase_38 AC 108 ms
76,624 KB
testcase_39 AC 94 ms
76,636 KB
testcase_40 AC 121 ms
82,440 KB
testcase_41 AC 115 ms
80,040 KB
testcase_42 AC 113 ms
82,436 KB
testcase_43 AC 94 ms
80,812 KB
testcase_44 WA -
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

int dp1[10010][1010],dp2[10010][1010];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,k;
  cin>>n>>k;
  vector<int> A(n+1);
  rep(i,n) cin>>A[i+1];
  
  dp1[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=k;j++){
      dp1[i][j]|=dp1[i-1][j];
      if(j-A[i]>=0) dp1[i][j]|=dp1[i-1][j-A[i]];
    }
  }
  dp2[n+1][0]=1;
  for(int i=n;i>=1;i--){
    for(int j=0;j<=k;j++){
      dp2[i][j]|=dp2[i-1][j];
      if(j-A[i]>=0) dp2[i][j]|=dp2[i+1][j-A[i]];
    }
  }
  
  int cnt=0;
  for(int i=1;i<=n;i++){
    bool b=true;
    for(int j=0;j<=k;j++){
      if(dp1[i-1][j] && dp2[i+1][k-j]) b=false;
    }
    if(b==false) continue;
    b=false;
    for(int j=0;j<=k-A[i];j++){
      if(dp1[i-1][j] && dp2[i+1][k-A[i]-j]) b=true;
    }
    if(b) cnt++;
  }
  if(dp1[n][k]==0) cout<<-1<<endl;
  else cout<<cnt<<endl;
  
  return 0;
}
0