結果

問題 No.868 ハイパー部分和問題
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-18 11:23:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,883 bytes
コンパイル時間 2,574 ms
コンパイル使用メモリ 196,308 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-08 23:45:38
合計ジャッジ時間 80,871 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 12 ms
6,944 KB
testcase_02 AC 18 ms
6,944 KB
testcase_03 AC 8 ms
6,948 KB
testcase_04 AC 5 ms
6,948 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
6,948 KB
testcase_08 AC 5 ms
6,948 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 5 ms
6,948 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 3,580 ms
6,948 KB
testcase_15 AC 3,577 ms
6,944 KB
testcase_16 AC 3,575 ms
6,948 KB
testcase_17 AC 3,572 ms
6,948 KB
testcase_18 AC 3,573 ms
6,948 KB
testcase_19 AC 2,453 ms
6,944 KB
testcase_20 AC 2,450 ms
6,944 KB
testcase_21 AC 2,453 ms
6,944 KB
testcase_22 AC 2,458 ms
6,944 KB
testcase_23 AC 2,453 ms
6,944 KB
testcase_24 AC 2,450 ms
6,948 KB
testcase_25 AC 2,457 ms
6,948 KB
testcase_26 AC 2,452 ms
6,944 KB
testcase_27 AC 2,455 ms
6,944 KB
testcase_28 AC 2,456 ms
6,944 KB
testcase_29 AC 3,218 ms
6,948 KB
testcase_30 AC 3,189 ms
6,948 KB
testcase_31 AC 3,190 ms
6,948 KB
testcase_32 AC 3,575 ms
6,948 KB
testcase_33 AC 3,578 ms
6,948 KB
testcase_34 AC 4,580 ms
6,944 KB
testcase_35 AC 4,565 ms
6,948 KB
testcase_36 AC 3,676 ms
6,944 KB
testcase_37 AC 3,680 ms
6,948 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 5 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int getrandmax() {
    static uint32_t y = time(NULL);
    y ^= (y << 13); y ^= (y >> 17);
    y ^= (y << 5);
    return abs((int)y);
}
int getrand(int l, int r) { // [l, r]
    return getrandmax() % (r - l + 1) + l;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, K, A[15101]; int Q;
const int MODS_COUNT = 1;
int dp[MODS_COUNT][50101];
const int MA = 15000;
int mods[10] = { 1000000007,1000000009,1000000021,1000000033,1000000087,1000000093,1000000097,1000000103,1000000123,1000000181 };
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	cin >> Q;

	rep(i, 0, 101) { int a = getrand(0, 9); int b = getrand(0, 9); swap(mods[a], mods[b]); }

	rep(mo, 0, MODS_COUNT) {
		dp[mo][0] = 1;
		rep(i, 0, N) if (0 < A[i]) rrep(k, MA * 2, 0) if (k + A[i] <= MA * 2) {
			dp[mo][k + A[i]] += dp[mo][k];
			dp[mo][k + A[i]] %= mods[mo];
		}
	}

	rep(q, 0, Q) {
		int x, v; cin >> x >> v;
		x--;

		// reverse
		if (0 < A[x]) {
			rep(mo, 0, MODS_COUNT) {
				rep(k, 0, MA * 2 + 1) if (0 <= k - A[x]) {
					dp[mo][k] -= dp[mo][k - A[x]];
					dp[mo][k] += mods[mo];
					dp[mo][k] %= mods[mo];
				}
			}
		}

		// change
		A[x] = v;

		// remake
		rep(mo, 0, MODS_COUNT) {
			dp[mo][0] = 1;
			if (0 < A[x]) rrep(k, MA * 2, 0) if (k + A[x] <= MA * 2) {
				dp[mo][k + A[x]] += dp[mo][k];
				dp[mo][k + A[x]] %= mods[mo];
			}
		}

		// check
		bool ok = false;
		rep(mo, 0, MODS_COUNT) if (0 < dp[mo][K]) ok = true;
		if (ok) printf("1\n");
		else printf("0\n");
	}
}






0