結果

問題 No.1861 Required Number
ユーザー ktr216ktr216
提出日時 2022-03-04 22:28:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 160 ms / 2,500 ms
コード長 1,881 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 173,824 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2023-09-26 03:44:10
合計ジャッジ時間 9,562 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 160 ms
6,680 KB
testcase_04 AC 160 ms
6,804 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,500 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 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,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 49 ms
4,496 KB
testcase_25 AC 121 ms
6,152 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 46 ms
5,180 KB
testcase_28 AC 53 ms
4,616 KB
testcase_29 AC 32 ms
4,580 KB
testcase_30 AC 12 ms
4,380 KB
testcase_31 AC 125 ms
5,944 KB
testcase_32 AC 14 ms
4,384 KB
testcase_33 AC 84 ms
5,532 KB
testcase_34 AC 99 ms
5,796 KB
testcase_35 AC 102 ms
6,020 KB
testcase_36 AC 35 ms
4,572 KB
testcase_37 AC 51 ms
5,236 KB
testcase_38 AC 104 ms
5,664 KB
testcase_39 AC 60 ms
4,888 KB
testcase_40 AC 124 ms
6,420 KB
testcase_41 AC 117 ms
6,260 KB
testcase_42 AC 97 ms
5,684 KB
testcase_43 AC 53 ms
5,416 KB
testcase_44 AC 1 ms
4,376 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;

using ll = long long;
using VI = vector<int>;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

template< typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true); }
template< typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true); }

const ll MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    VI A(N);
    REP(i, N) cin >> A[i];
    vector<vector<bool>> L(N + 1, vector<bool>(K + 1, false));
    vector<vector<bool>> R(N + 1, vector<bool>(K + 1, false));
    L[0][0] = true;
    R[N][0] = true;
    REP(i, N) {
        REP(j, K + 1) {
            L[i + 1][j] = L[i + 1][j] | L[i][j];
            if (j + A[i] <= K) L[i + 1][j + A[i]] = L[i + 1][j + A[i]] | L[i][j];
            R[N - i - 1][j] = R[N - i - 1][j] | R[N - i][j];
            if (j + A[N - 1 - i] <= K) R[N - i - 1][j + A[N - 1 - i]] = R[N - i - 1][j + A[N - 1 - i]] | R[N - i][j];
        }
    }
    if (!L[N][K]) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    REP(i, N) {
        bool f = true, g = false;
        REP(j, K + 1) {
            if (L[i][j]) {
                if (R[i + 1][K - j]) f = false;
                if (j + A[i] <= K && R[i + 1][K - j - A[i]]) g = true;
            }
        }
        if (f && g) {
           // cout << i << endl;
            ans++;
        }
    }
    cout << ans << endl;
    /*
    REP(i, N + 1) {
        REP(j, K + 1) cout << L[i][j];
        cout << endl;
        REP(j, K + 1) cout << R[i][j];
        cout << endl << endl;
    }
    */
}
0