結果

問題 No.1861 Required Number
ユーザー RaffRaff
提出日時 2022-03-07 20:27:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,500 ms
コード長 1,555 bytes
コンパイル時間 1,392 ms
コンパイル使用メモリ 168,692 KB
実行使用メモリ 23,068 KB
最終ジャッジ日時 2023-09-29 21:49:06
合計ジャッジ時間 4,269 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 44 ms
23,028 KB
testcase_04 AC 44 ms
23,068 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 17 ms
9,916 KB
testcase_25 AC 38 ms
20,248 KB
testcase_26 AC 10 ms
6,116 KB
testcase_27 AC 15 ms
9,184 KB
testcase_28 AC 17 ms
10,476 KB
testcase_29 AC 12 ms
7,128 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 39 ms
20,608 KB
testcase_32 AC 6 ms
4,664 KB
testcase_33 AC 28 ms
15,032 KB
testcase_34 AC 31 ms
17,108 KB
testcase_35 AC 32 ms
17,344 KB
testcase_36 AC 13 ms
7,420 KB
testcase_37 AC 18 ms
9,840 KB
testcase_38 AC 33 ms
17,664 KB
testcase_39 AC 19 ms
11,096 KB
testcase_40 AC 38 ms
20,544 KB
testcase_41 AC 36 ms
19,388 KB
testcase_42 AC 30 ms
16,444 KB
testcase_43 AC 18 ms
10,088 KB
testcase_44 AC 1 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;

#define rep(i, f, n) for (int i = (f); i < (n); i++)
#define rrep(i, f, n) for (int i = int(n) - 1; i >= f; i--)
typedef long long ll;
typedef pair<int, int> P;

template <typename T, typename U>
auto Sum(T a, U b) -> decltype(a + b)
{
    return a + b;
}

template <typename T, typename U>
inline bool amax(T &a, U b)
{
    if (b > a)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T, typename U>
inline bool amin(T &a, U b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N + 1);
    rep(i, 1, N + 1) cin >> A[i];

    bool dpl[N + 2][K + 1], dpr[N + 2][K + 1];
    rep(i, 0, N + 2) rep(j, 0, K + 2)
    {
        dpl[i][j] = false;
        dpr[i][j] = false;
    }
    dpl[0][0] = true;
    dpr[N + 1][0] = true;
    rep(i, 1, N + 1) rep(j, 0, K + 1)
    {
        dpl[i][j] = dpl[i - 1][j];
        if (j >= A[i])
            dpl[i][j] |= dpl[i - 1][j - A[i]];
    }
    rrep(i, 1, N + 1) rep(j, 0, K + 1)
    {
        dpr[i][j] = dpr[i + 1][j];
        if (j >= A[i])
            dpr[i][j] |= dpr[i + 1][j - A[i]];
    }

    if (!dpl[N][K])
    {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    rep(i, 1, N + 1)
    {
        bool ok = true;
        rep(j, 0, K + 1)
        {
            if (dpl[i - 1][j] && dpr[i + 1][K - j])
                ok = false;
        }
        if (ok)
            ans++;
    }
    cout << ans << endl;
}
0