結果

問題 No.868 ハイパー部分和問題
ユーザー lumc_lumc_
提出日時 2019-08-17 10:58:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,597 ms / 7,000 ms
コード長 1,383 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 109,580 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 00:00:36
合計ジャッジ時間 34,702 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 2 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 2,453 ms
4,348 KB
testcase_15 AC 2,450 ms
4,348 KB
testcase_16 AC 2,456 ms
4,348 KB
testcase_17 AC 2,448 ms
4,348 KB
testcase_18 AC 2,443 ms
4,348 KB
testcase_19 AC 77 ms
4,348 KB
testcase_20 AC 77 ms
4,348 KB
testcase_21 AC 113 ms
4,348 KB
testcase_22 AC 113 ms
4,348 KB
testcase_23 AC 149 ms
4,348 KB
testcase_24 AC 149 ms
4,348 KB
testcase_25 AC 184 ms
4,348 KB
testcase_26 AC 185 ms
4,348 KB
testcase_27 AC 220 ms
4,348 KB
testcase_28 AC 217 ms
4,348 KB
testcase_29 AC 1,978 ms
4,348 KB
testcase_30 AC 1,967 ms
4,348 KB
testcase_31 AC 1,968 ms
4,348 KB
testcase_32 AC 2,445 ms
4,348 KB
testcase_33 AC 2,470 ms
4,348 KB
testcase_34 AC 2,597 ms
4,348 KB
testcase_35 AC 2,591 ms
4,348 KB
testcase_36 AC 1,159 ms
4,348 KB
testcase_37 AC 1,165 ms
4,348 KB
testcase_38 AC 8 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

constexpr int B = 300;

constexpr int N = 1.5e4;
int n, k, q;
int a[N];
int x[N], v[N];

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> x[i] >> v[i];
    x[i]--;
  }
  vector<int> use(n, -1);
  vector<int> after;
  // O(Q/B)
  for(int i = 0; i < q; i+=B) {
    after.clear();

    bitset<N + 1> dp;
    dp[0] = 1;
    // O(B)
    for(int j = i; j < min<int>(q, i + B); j++) {
      use[x[j]] = i;
    }
    // O(N^2 / 64)
    for(int j = 0; j < n; j++) {
      if(use[j] != i) dp |= dp << a[j];
      else after.push_back(j);
    }
    // O(B)
    for(int j = i; j < min<int>(q, i + B); j++) {
      auto dp2 = dp;
      // O(BN / 64)
      for(auto p : after) if(p != x[j]) dp2 |= dp2 << a[p];
      dp2 |= dp2 << v[j];
      cout << dp2[k] << "\n";
      a[x[j]] = v[j];
    }
  }
  

  // O(Q/B(N^2 + B^2N) / 64)
  // = O(N^2Q/B + QBN / 64)

  return 0;
}
0