結果

問題 No.1861 Required Number
ユーザー umezoumezo
提出日時 2022-03-04 22:37:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 200,688 KB
実行使用メモリ 82,456 KB
最終ジャッジ日時 2023-09-26 03:45:27
合計ジャッジ時間 12,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,452 KB
testcase_01 AC 2 ms
5,512 KB
testcase_02 AC 2 ms
5,444 KB
testcase_03 AC 129 ms
82,456 KB
testcase_04 AC 128 ms
82,384 KB
testcase_05 AC 2 ms
5,496 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 3 ms
6,416 KB
testcase_09 AC 2 ms
5,556 KB
testcase_10 AC 2 ms
5,604 KB
testcase_11 AC 2 ms
5,556 KB
testcase_12 AC 2 ms
5,692 KB
testcase_13 AC 3 ms
5,688 KB
testcase_14 AC 2 ms
5,496 KB
testcase_15 AC 2 ms
5,812 KB
testcase_16 AC 3 ms
5,736 KB
testcase_17 AC 2 ms
5,556 KB
testcase_18 WA -
testcase_19 AC 3 ms
5,904 KB
testcase_20 AC 3 ms
5,756 KB
testcase_21 AC 2 ms
5,712 KB
testcase_22 AC 3 ms
5,836 KB
testcase_23 AC 2 ms
5,536 KB
testcase_24 AC 58 ms
40,028 KB
testcase_25 AC 131 ms
80,052 KB
testcase_26 AC 57 ms
48,076 KB
testcase_27 AC 94 ms
72,340 KB
testcase_28 AC 82 ms
60,056 KB
testcase_29 AC 93 ms
76,764 KB
testcase_30 AC 86 ms
80,324 KB
testcase_31 AC 131 ms
76,936 KB
testcase_32 AC 85 ms
77,180 KB
testcase_33 AC 116 ms
76,904 KB
testcase_34 AC 122 ms
76,696 KB
testcase_35 AC 131 ms
81,884 KB
testcase_36 AC 93 ms
76,948 KB
testcase_37 AC 106 ms
81,844 KB
testcase_38 AC 121 ms
76,840 KB
testcase_39 AC 103 ms
76,576 KB
testcase_40 AC 139 ms
82,352 KB
testcase_41 AC 132 ms
80,000 KB
testcase_42 AC 128 ms
82,364 KB
testcase_43 AC 105 ms
80,684 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];
  
  if(k==0){
    int cnt=0;
    rep(i,n){
      if(A[i+1]==0) cnt++;
    }
    if(cnt>1) cout<<0<<endl;
    else if(cnt==1) cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }
  
  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