結果

問題 No.868 ハイパー部分和問題
ユーザー finefine
提出日時 2019-08-23 23:37:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,046 ms / 7,000 ms
コード長 1,129 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 167,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:55:23
合計ジャッジ時間 13,874 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 528 ms
5,376 KB
testcase_15 AC 526 ms
5,376 KB
testcase_16 AC 533 ms
5,376 KB
testcase_17 AC 529 ms
5,376 KB
testcase_18 AC 526 ms
5,376 KB
testcase_19 AC 355 ms
5,376 KB
testcase_20 AC 363 ms
5,376 KB
testcase_21 AC 358 ms
5,376 KB
testcase_22 AC 368 ms
5,376 KB
testcase_23 AC 354 ms
5,376 KB
testcase_24 AC 357 ms
5,376 KB
testcase_25 AC 363 ms
5,376 KB
testcase_26 AC 354 ms
5,376 KB
testcase_27 AC 359 ms
5,376 KB
testcase_28 AC 366 ms
5,376 KB
testcase_29 AC 258 ms
5,376 KB
testcase_30 AC 257 ms
5,376 KB
testcase_31 AC 271 ms
5,376 KB
testcase_32 AC 530 ms
5,376 KB
testcase_33 AC 526 ms
5,376 KB
testcase_34 AC 1,043 ms
5,376 KB
testcase_35 AC 1,046 ms
5,376 KB
testcase_36 AC 592 ms
5,376 KB
testcase_37 AC 585 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 998462417;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

const int MAXK = 15000;

ll dp[MAXK + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) continue;
        for (int j = K; j >= a[i]; j--) {
            (dp[j] += dp[j - a[i]]) %= MOD;
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x, v;
        cin >> x >> v;
        x--;
        
        for (int j = a[x]; j <= K; j++) {
            if (a[x] == 0) break;
            (dp[j] += (MOD - dp[j - a[x]])) %= MOD;
        }

        a[x] = v;
        for (int j = K; j >= v; j--) {
            if (v == 0) break;
            (dp[j] += dp[j - v]) %= MOD;
        }

        cout << (dp[K] > 0) << "\n";
    }
    return 0;
}
0