結果

問題 No.1861 Required Number
ユーザー MtSakaMtSaka
提出日時 2021-12-27 03:05:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,500 ms
コード長 697 bytes
コンパイル時間 3,428 ms
コンパイル使用メモリ 223,436 KB
実行使用メモリ 5,952 KB
最終ジャッジ日時 2023-09-26 02:59:19
合計ジャッジ時間 6,015 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 16 ms
5,716 KB
testcase_04 AC 16 ms
5,624 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 6 ms
5,528 KB
testcase_26 AC 4 ms
4,392 KB
testcase_27 AC 6 ms
5,216 KB
testcase_28 AC 5 ms
4,764 KB
testcase_29 AC 6 ms
5,412 KB
testcase_30 AC 6 ms
5,464 KB
testcase_31 AC 6 ms
5,420 KB
testcase_32 AC 5 ms
5,448 KB
testcase_33 AC 6 ms
5,356 KB
testcase_34 AC 6 ms
5,288 KB
testcase_35 AC 6 ms
5,296 KB
testcase_36 AC 5 ms
5,420 KB
testcase_37 AC 7 ms
5,516 KB
testcase_38 AC 6 ms
5,424 KB
testcase_39 AC 5 ms
5,300 KB
testcase_40 AC 6 ms
5,952 KB
testcase_41 AC 6 ms
5,296 KB
testcase_42 AC 6 ms
5,600 KB
testcase_43 AC 6 ms
5,524 KB
testcase_44 AC 2 ms
4,376 KB
04_evil_1.txt WA -
04_evil_2.txt WA -
04_evil_3.txt WA -
04_evil_4.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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;
        break;
      }
    }
    if(flag)ans++;
  }
  cout<<ans<<endl;
}
0