結果

問題 No.868 ハイパー部分和問題
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-17 01:01:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,540 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 128,936 KB
実行使用メモリ 4,604 KB
最終ジャッジ日時 2023-10-24 16:33:04
合計ジャッジ時間 61,980 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 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 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 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 5,404 ms
4,572 KB
testcase_15 AC 5,375 ms
4,572 KB
testcase_16 AC 5,394 ms
4,572 KB
testcase_17 AC 5,368 ms
4,572 KB
testcase_18 AC 5,367 ms
4,572 KB
testcase_19 AC 956 ms
4,456 KB
testcase_20 AC 953 ms
4,456 KB
testcase_21 AC 959 ms
4,456 KB
testcase_22 AC 952 ms
4,456 KB
testcase_23 AC 958 ms
4,456 KB
testcase_24 AC 964 ms
4,456 KB
testcase_25 AC 958 ms
4,456 KB
testcase_26 AC 954 ms
4,456 KB
testcase_27 AC 957 ms
4,456 KB
testcase_28 AC 956 ms
4,456 KB
testcase_29 AC 655 ms
4,572 KB
testcase_30 AC 650 ms
4,572 KB
testcase_31 AC 658 ms
4,572 KB
testcase_32 AC 1,309 ms
4,572 KB
testcase_33 AC 1,310 ms
4,572 KB
testcase_34 TLE -
testcase_35 TLE -
testcase_36 AC 1,427 ms
4,572 KB
testcase_37 AC 1,420 ms
4,572 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>

#include <random>

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 H = 8;
int MOs[10];
int dp[10][20010];

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

int main() {
  MOs[0] = 998244353;
  MOs[1] = 1000000007;
  MOs[2] = 1000000009;
  
  random_device device;
  mt19937 rng(device());
  uniform_int_distribution<int> distr(505005005, 1001001001);
  for (int h = 3; h < H; ++h) {
    MOs[h] = distr(rng);
  }
// cerr<<"MOs = ";pv(MOs,MOs+H);
  
  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[0],dp[0]+K+1);
// pv(dp[1],dp[1]+K+1);
      printf("%d\n", get());
    }
  }
  return 0;
}
0