結果

問題 No.868 ハイパー部分和問題
ユーザー niuezniuez
提出日時 2019-08-17 10:18:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,096 ms / 7,000 ms
コード長 957 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 170,532 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 23:57:36
合計ジャッジ時間 14,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 895 ms
4,372 KB
testcase_15 AC 895 ms
4,372 KB
testcase_16 AC 894 ms
4,372 KB
testcase_17 AC 890 ms
4,372 KB
testcase_18 AC 890 ms
4,372 KB
testcase_19 AC 255 ms
4,372 KB
testcase_20 AC 257 ms
4,372 KB
testcase_21 AC 256 ms
4,372 KB
testcase_22 AC 256 ms
4,372 KB
testcase_23 AC 255 ms
4,372 KB
testcase_24 AC 255 ms
4,372 KB
testcase_25 AC 258 ms
4,372 KB
testcase_26 AC 256 ms
4,372 KB
testcase_27 AC 256 ms
4,372 KB
testcase_28 AC 255 ms
4,372 KB
testcase_29 AC 202 ms
4,372 KB
testcase_30 AC 201 ms
4,372 KB
testcase_31 AC 204 ms
4,372 KB
testcase_32 AC 374 ms
4,372 KB
testcase_33 AC 374 ms
4,372 KB
testcase_34 AC 1,096 ms
4,372 KB
testcase_35 AC 1,089 ms
4,372 KB
testcase_36 AC 405 ms
4,372 KB
testcase_37 AC 406 ms
4,372 KB
testcase_38 AC 2 ms
4,372 KB
testcase_39 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N + 1);
  rep(i,1,N + 1) cin >> A[i];
  i64 mod = (1ll << 55) + 55;
  vector<i64> dp(K + 1, 0);
  dp[0] = 1;

  auto fix = [mod](i64 m) {
    if(m < 0) return m + mod;
    if(m >= mod) return m - mod;
    return m;
  };

  rep(i,1,N + 1) {
    if(A[i] != 0) {
      for(int j = K; j >= A[i]; j--) {
        dp[j] = fix(dp[j] + dp[j - A[i]]);
      }
    }
  }

  i64 Q;
  cin >> Q;

  rep(q, 0, Q) {
    i64 x, v;
    cin >> x >> v;
    if(A[x] != 0) {
      for(int j = A[x]; j <= K; j++) {
        dp[j] = fix(dp[j] - dp[j - A[x]]);
      }
    }
    A[x] = v;
    if(A[x] != 0) {
      for(int j = K; j >= A[x]; j--) {
        dp[j] = fix(dp[j] + dp[j - A[x]]);
      }
    }
    cout << (dp[K] != 0) << endl;
  }
}
0