結果

問題 No.868 ハイパー部分和問題
ユーザー QCFiumQCFium
提出日時 2019-08-16 23:18:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,241 ms / 7,000 ms
コード長 1,210 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 178,808 KB
実行使用メモリ 31,696 KB
最終ジャッジ日時 2023-10-24 16:12:35
合計ジャッジ時間 45,255 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 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 3 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,905 ms
31,696 KB
testcase_15 AC 2,922 ms
31,696 KB
testcase_16 AC 2,925 ms
31,696 KB
testcase_17 AC 2,923 ms
31,696 KB
testcase_18 AC 2,913 ms
31,696 KB
testcase_19 AC 66 ms
4,348 KB
testcase_20 AC 67 ms
4,348 KB
testcase_21 AC 86 ms
4,348 KB
testcase_22 AC 86 ms
4,348 KB
testcase_23 AC 104 ms
4,348 KB
testcase_24 AC 105 ms
4,348 KB
testcase_25 AC 122 ms
4,348 KB
testcase_26 AC 123 ms
4,348 KB
testcase_27 AC 139 ms
4,348 KB
testcase_28 AC 138 ms
4,348 KB
testcase_29 AC 2,616 ms
31,696 KB
testcase_30 AC 2,629 ms
31,696 KB
testcase_31 AC 2,609 ms
31,696 KB
testcase_32 AC 2,895 ms
31,696 KB
testcase_33 AC 2,900 ms
31,696 KB
testcase_34 AC 3,241 ms
31,696 KB
testcase_35 AC 3,237 ms
31,696 KB
testcase_36 AC 2,806 ms
31,692 KB
testcase_37 AC 2,813 ms
31,692 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int n = ri(), real_k = ri();
	std::pair<int, int> a[n];
	for (int i = 0; i < n; i++) a[i] = {ri(), i};
	int q = ri();
	int x[q], v[q];
	for (int i = 0; i < q; i++) {
		x[i] = ri() - 1;
		v[i] = ri();
	}
	int pos[n];
	for (int i = 0; i < n; i++) pos[i] = i;
	for (int i = 0; i < q; i += 100) {
		std::map<int, int> cnt;
		for (int j = i; j < q && j < i + 100; j++) {
			cnt[x[j]]++;
		}
		std::pair<int, int> new_a[n];
		int cur = 0;
		for (int i = 0; i < n; i++) {
			if (!cnt.count(a[i].second)) new_a[cur++] = a[i];
		}
		for (auto i : cnt) new_a[cur++] = a[pos[i.first]];
		assert(cur == n);
		memcpy(a, new_a, sizeof(new_a));
		for (int i = 0; i < n; i++) pos[a[i].second] = i;
		std::bitset<15001> set[n + 1];
		set[0] = std::bitset<15001>(1);
		for (int i = 0; i < n; i++) set[i + 1] = set[i] | set[i] << a[i].first;
		for (int j = i; j < q && j < i + 100; j++) {
			int k = pos[x[j]];
			a[k].first = v[j];
			for (int l = k; l < n; l++) set[l + 1] = set[l] | set[l] << a[l].first;
			std::cout << set[n][real_k] << std::endl;
		}
	}
	
	return 0;
}
0