結果

問題 No.1861 Required Number
ユーザー MtSakaMtSaka
提出日時 2021-12-27 03:03:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,500 ms
コード長 574 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 204,220 KB
実行使用メモリ 32,876 KB
最終ジャッジ日時 2023-09-26 02:59:34
合計ジャッジ時間 14,839 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
32,800 KB
testcase_02 AC 2 ms
32,876 KB
testcase_03 AC 22 ms
10,200 KB
testcase_04 AC 22 ms
10,196 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 11 ms
4,380 KB
testcase_25 AC 24 ms
5,372 KB
testcase_26 AC 7 ms
4,424 KB
testcase_27 AC 12 ms
5,272 KB
testcase_28 AC 13 ms
4,888 KB
testcase_29 AC 10 ms
5,292 KB
testcase_30 AC 7 ms
5,448 KB
testcase_31 AC 24 ms
5,420 KB
testcase_32 AC 7 ms
5,512 KB
testcase_33 AC 18 ms
5,504 KB
testcase_34 AC 21 ms
5,672 KB
testcase_35 AC 22 ms
5,448 KB
testcase_36 AC 10 ms
5,360 KB
testcase_37 AC 13 ms
5,404 KB
testcase_38 AC 21 ms
5,348 KB
testcase_39 AC 14 ms
5,360 KB
testcase_40 AC 25 ms
5,592 KB
testcase_41 AC 23 ms
5,296 KB
testcase_42 AC 21 ms
5,720 KB
testcase_43 AC 14 ms
5,416 KB
testcase_44 AC 2 ms
4,380 KB
04_evil_1.txt TLE -
04_evil_2.txt TLE -
04_evil_3.txt WA -
04_evil_4.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

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<bitset<1001>>dpl(N+1),dpr(N+2);
  dpl[0][0]=dpr[N+1][0]=1;
  for(int i=0;i<N;i++){
    dpl[i+1]=dpl[i]|(dpl[i]<<A[i]);
  }
  for(int i=N-1;i>=0;i--){
    dpr[i+1]=dpr[i+2]|(dpr[i+2]<<A[i]);
  }
  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