結果

問題 No.868 ハイパー部分和問題
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-16 22:19:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,961 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 113,948 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 14:35:03
合計ジャッジ時間 5,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 120 ms
4,348 KB
testcase_15 AC 119 ms
4,348 KB
testcase_16 AC 119 ms
4,348 KB
testcase_17 AC 120 ms
4,348 KB
testcase_18 AC 121 ms
4,348 KB
testcase_19 AC 75 ms
4,348 KB
testcase_20 AC 75 ms
4,348 KB
testcase_21 AC 76 ms
4,348 KB
testcase_22 AC 76 ms
4,348 KB
testcase_23 AC 75 ms
4,348 KB
testcase_24 AC 76 ms
4,348 KB
testcase_25 AC 76 ms
4,348 KB
testcase_26 AC 75 ms
4,348 KB
testcase_27 AC 76 ms
4,348 KB
testcase_28 AC 75 ms
4,348 KB
testcase_29 AC 64 ms
4,348 KB
testcase_30 AC 63 ms
4,348 KB
testcase_31 AC 64 ms
4,348 KB
testcase_32 AC 121 ms
4,348 KB
testcase_33 AC 121 ms
4,348 KB
testcase_34 AC 402 ms
4,348 KB
testcase_35 AC 400 ms
4,348 KB
testcase_36 AC 133 ms
4,348 KB
testcase_37 AC 133 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int N, K;
int A[20010];
int Q;
int X[20010], V[20010];

int a[20010];

constexpr int MO = 998244353;
int dp[20010];

void init() {
  fill(dp, dp + K + 1, 0);
  dp[0] = 1;
}
void add(int x) {
  if (x != 0) {
    for (int j = K; j >= x; --j) {
      if ((dp[j] += dp[j - x]) >= MO) {
        dp[j] -= MO;
      }
    }
  }
}
void remove(int x) {
  if (x != 0) {
    for (int j = x; j <= K; ++j) {
      if ((dp[j] -= dp[j - x]) < 0) {
        dp[j] += MO;
      }
    }
  }
}
int get() {
  return (dp[K] != 0) ? 1 : 0;
}

int main() {
  for (; ~scanf("%d%d", &N, &K); ) {
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    scanf("%d", &Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d", &X[q], &V[q]);
      --X[q];
    }
    
    init();
    for (int i = 0; i < N; ++i) {
      add(A[i]);
    }
    copy(A, A + N, a);
    
    for (int q = 0; q < Q; ++q) {
      remove(a[X[q]]);
      a[X[q]] = V[q];
      add(a[X[q]]);
// pv(a,a+N);
// pv(dp,dp+K+1);
      printf("%d\n", get());
    }
  }
  return 0;
}
0