結果

問題 No.868 ハイパー部分和問題
ユーザー e869120e869120
提出日時 2019-08-16 14:31:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,273 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 79,272 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:45:17
合計ジャッジ時間 15,761 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_05 RE -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 1,460 ms
4,348 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 1,174 ms
4,348 KB
testcase_30 AC 1,179 ms
4,348 KB
testcase_31 AC 1,169 ms
4,348 KB
testcase_32 AC 1,462 ms
4,348 KB
testcase_33 AC 1,464 ms
4,348 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 1,087 ms
4,348 KB
testcase_37 AC 1,073 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;

const int BACKET = 130;
int N, K, Q, A[15009], X[15009], V[15009], ans[15009];
bool used[15009];
bitset<15009>ZERO;

void query(int cl, int cr) {
	for (int i = 1; i <= N; i++) used[i] = false;
	vector<int> J;
	for (int i = cl; i <= cr; i++) { used[X[i]] = true; J.push_back(X[i]); }
	sort(J.begin(), J.end());
	J.erase(unique(J.begin(), J.end()), J.end());

	bitset<15009> G = ZERO; G.set(0);
	for (int i = 1; i <= N; i++) {
		if (used[i] == false) G |= (G << A[i]);
	}

	for (int i = cl; i <= cr; i++) {
		A[X[i]] = V[i];
		bitset<15009>H = G;
		for (int pos : J) H |= (H << A[pos]);
		if (H[K] == 1) ans[i] = 1;
		else ans[i] = 0;
	}
}

int main() {
	cin >> N >> K;
	assert(1 <= N && N <= 15000);
	assert(1 <= K && K <= 15000);
	for (int i = 1; i <= N; i++) { cin >> A[i]; assert(1 <= A[i] && A[i] <= 15000); }
	cin >> Q;
	assert(1 <= Q && Q <= 15000);
	for (int i = 1; i <= Q; i++) {
		cin >> X[i] >> V[i];
		assert(1 <= X[i] && X[i] <= N);
		assert(1 <= V[i] && V[i] <= 15000);
	}

	for (int i = 1; i <= Q; i += BACKET) {
		int cl = i, cr = min(Q, i + BACKET - 1);
		query(cl, cr);
	}
	for (int i = 1; i <= Q; i++) cout << ans[i] << endl;
	return 0;
}
0