結果

問題 No.1861 Required Number
ユーザー sushitorunasushitoruna
提出日時 2021-12-27 01:27:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,500 ms
コード長 985 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 168,320 KB
実行使用メモリ 23,132 KB
最終ジャッジ日時 2023-09-26 02:54:48
合計ジャッジ時間 4,902 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 49 ms
23,000 KB
testcase_04 AC 48 ms
23,132 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 16 ms
9,924 KB
testcase_25 AC 39 ms
20,188 KB
testcase_26 AC 9 ms
6,368 KB
testcase_27 AC 16 ms
9,212 KB
testcase_28 AC 18 ms
10,236 KB
testcase_29 AC 12 ms
7,232 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 40 ms
20,772 KB
testcase_32 AC 7 ms
4,708 KB
testcase_33 AC 29 ms
15,004 KB
testcase_34 AC 33 ms
17,132 KB
testcase_35 AC 34 ms
17,492 KB
testcase_36 AC 13 ms
7,380 KB
testcase_37 AC 18 ms
9,832 KB
testcase_38 AC 33 ms
17,636 KB
testcase_39 AC 20 ms
11,148 KB
testcase_40 AC 39 ms
20,368 KB
testcase_41 AC 37 ms
19,432 KB
testcase_42 AC 31 ms
16,620 KB
testcase_43 AC 18 ms
10,128 KB
testcase_44 AC 2 ms
4,380 KB
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
  //入力
  int N,K;cin>>N>>K;
  vector<int>A(N+1);
  for(int i=1;i<=N;i++)cin>>A[i];
  
  //dpの前処理
  bool dpl[N+2][K+1],dpr[N+2][K+1];
  for(int i=0;i<N+2;i++)for(int j=0;j<=K;j++)dpl[i][j]=false,dpr[i][j]=false;
  //dpl[i][j]:=A_1~A_iから選んで、和をjにできるか
  //dpr[i][j]:=A_i~A_Nから選んで、和をjにできるか
  dpl[0][0]=true;dpr[N+1][0]=true;
  for(int i=1;i<=N;i++)for(int j=0;j<=K;j++)
  {
    dpl[i][j]=dpl[i-1][j];
    if(j<A[i])continue;
    if(dpl[i-1][j-A[i]])dpl[i][j]=true;
  }
  for(int i=N;i>=1;i--)for(int j=0;j<=K;j++)
  {
    dpr[i][j]=dpr[i+1][j];
    if(j<A[i])continue;
    if(dpr[i+1][j-A[i]])dpr[i][j]=true;
  }
  
  //判定
  if(!dpl[N][K]){cout<<-1<<endl;return 0;}

  int ans=0;
  for(int i=1;i<=N;i++)
  {
    bool check=true;
    for(int j=0;j<=K;j++)
      if(dpl[i-1][j]&&dpr[i+1][K-j])check=false;
    if(check)ans++;
  }
  
  //出力
  cout<<ans<<endl;
}
0