結果

問題 No.868 ハイパー部分和問題
ユーザー square1001square1001
提出日時 2019-08-16 22:08:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 898 ms / 7,000 ms
コード長 1,118 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 89,248 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 14:34:25
合計ジャッジ時間 6,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 128 ms
4,348 KB
testcase_15 AC 127 ms
4,348 KB
testcase_16 AC 129 ms
4,348 KB
testcase_17 AC 127 ms
4,348 KB
testcase_18 AC 127 ms
4,348 KB
testcase_19 AC 84 ms
4,348 KB
testcase_20 AC 84 ms
4,348 KB
testcase_21 AC 85 ms
4,348 KB
testcase_22 AC 86 ms
4,348 KB
testcase_23 AC 84 ms
4,348 KB
testcase_24 AC 85 ms
4,348 KB
testcase_25 AC 85 ms
4,348 KB
testcase_26 AC 84 ms
4,348 KB
testcase_27 AC 84 ms
4,348 KB
testcase_28 AC 84 ms
4,348 KB
testcase_29 AC 62 ms
4,348 KB
testcase_30 AC 61 ms
4,348 KB
testcase_31 AC 63 ms
4,348 KB
testcase_32 AC 119 ms
4,348 KB
testcase_33 AC 119 ms
4,348 KB
testcase_34 AC 898 ms
4,348 KB
testcase_35 AC 892 ms
4,348 KB
testcase_36 AC 128 ms
4,348 KB
testcase_37 AC 129 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <random>
#include <iostream>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
using namespace std;
int N, K, Q, mod, A[15009], dp[15009];
bool isprime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; ++i) {
		if (x % i == 0) return false;
	}
	return true;
}
int main() {
	random_device rd;
	uniform_int_distribution<int> p(600000000, 1050000000);
	while (!isprime(mod)) mod = p(rd);
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> K;
	for (int i = 0; i < N; ++i) cin >> A[i];
	dp[0] = 1;
	for (int i = 0; i < N; ++i) {
		if (A[i] > 0) {
			for (int j = K; j >= A[i]; --j) {
				dp[j] += dp[j - A[i]];
				if (dp[j] >= mod) dp[j] -= mod;
			}
		}
	}
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int x, v;
		cin >> x >> v; --x;
		if (A[x] > 0) {
			for (int j = A[x]; j <= K; ++j) {
				dp[j] -= dp[j - A[x]];
				if (dp[j] < 0) dp[j] += mod;
				if (dp[j] < 0) dp[j] += mod;
			}
		}
		A[x] = v;
		if (A[x] > 0) {
			for (int j = K; j >= A[x]; --j) {
				dp[j] += dp[j - A[x]];
				if (dp[j] >= mod) dp[j] -= mod;
			}
		}
		cout << (dp[K] > 0 ? 1 : 0) << '\n';
	}
	return 0;
}
0