結果

問題 No.1861 Required Number
ユーザー shiomusubi496shiomusubi496
提出日時 2022-02-24 22:45:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,500 ms
コード長 950 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 206,956 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-09-26 02:59:46
合計ジャッジ時間 10,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 97 ms
6,748 KB
testcase_04 AC 97 ms
6,736 KB
testcase_05 AC 2 ms
4,388 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,388 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 21 ms
4,408 KB
testcase_25 AC 49 ms
6,216 KB
testcase_26 AC 14 ms
4,380 KB
testcase_27 AC 21 ms
4,892 KB
testcase_28 AC 25 ms
4,628 KB
testcase_29 AC 16 ms
4,632 KB
testcase_30 AC 10 ms
4,504 KB
testcase_31 AC 52 ms
6,016 KB
testcase_32 AC 8 ms
4,464 KB
testcase_33 AC 35 ms
5,544 KB
testcase_34 AC 40 ms
5,796 KB
testcase_35 AC 42 ms
5,904 KB
testcase_36 AC 18 ms
4,624 KB
testcase_37 AC 23 ms
5,156 KB
testcase_38 AC 43 ms
5,632 KB
testcase_39 AC 29 ms
4,836 KB
testcase_40 AC 52 ms
6,420 KB
testcase_41 AC 48 ms
6,220 KB
testcase_42 AC 38 ms
5,644 KB
testcase_43 AC 25 ms
4,952 KB
testcase_44 AC 1 ms
4,384 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

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<vector<bool>> dpl(N + 1, vector<bool>(K + 1, false));
    vector<vector<bool>> dpr(N + 1, vector<bool>(K + 1, false));
    dpl[0][0] = dpr[N][0] = true;
    for (int i=0; i<N; ++i) {
        dpl[i + 1] = dpl[i];
        for (int j=0; j+A[i]<=K; ++j) dpl[i + 1][j + A[i]] = dpl[i + 1][j + A[i]] || dpl[i][j];
    }
    for (int i=N-1; i>=0; --i) {
        dpr[i] = dpr[i + 1];
        for (int j=0; j+A[i]<=K; ++j) dpr[i][j + A[i]] = dpr[i][j + A[i]] || dpr[i + 1][j];
    }
    if (!dpl[N][K]) {
        puts("-1");
        return 0;
    }
    int ans = 0;
    for (int i=0; i<N; ++i) {
        bool not_use = true;
        for (int j=0; j<=K; ++j) {
            if (dpl[i][j] && dpr[i + 1][K - j]) not_use = false;
        }
        if (not_use) ++ans;
    }
    cout << ans << endl;
}
0