結果

問題 No.973 余興
ユーザー QCFiumQCFium
提出日時 2020-01-17 22:44:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,933 bytes
コンパイル時間 1,927 ms
コンパイル使用メモリ 176,304 KB
実行使用メモリ 48,560 KB
最終ジャッジ日時 2023-09-08 05:38:05
合計ジャッジ時間 56,228 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,473 ms
48,180 KB
testcase_01 AC 3,345 ms
48,180 KB
testcase_02 AC 3,261 ms
48,324 KB
testcase_03 AC 3,287 ms
48,460 KB
testcase_04 AC 3,299 ms
48,368 KB
testcase_05 AC 3,281 ms
48,324 KB
testcase_06 AC 3,318 ms
48,240 KB
testcase_07 AC 3,452 ms
48,484 KB
testcase_08 AC 3,289 ms
47,948 KB
testcase_09 AC 3,438 ms
48,560 KB
testcase_10 AC 3,157 ms
46,888 KB
testcase_11 AC 1,720 ms
18,284 KB
testcase_12 AC 1,720 ms
18,568 KB
testcase_13 AC 1,724 ms
18,352 KB
testcase_14 AC 1,709 ms
18,204 KB
testcase_15 AC 81 ms
5,120 KB
testcase_16 AC 81 ms
5,072 KB
testcase_17 AC 51 ms
4,536 KB
testcase_18 AC 64 ms
4,732 KB
testcase_19 AC 66 ms
4,744 KB
testcase_20 AC 49 ms
4,424 KB
testcase_21 AC 81 ms
5,116 KB
testcase_22 AC 81 ms
4,968 KB
testcase_23 AC 66 ms
4,800 KB
testcase_24 AC 65 ms
4,696 KB
testcase_25 AC 30 ms
4,376 KB
testcase_26 AC 50 ms
4,424 KB
testcase_27 AC 100 ms
5,712 KB
testcase_28 AC 65 ms
4,880 KB
testcase_29 AC 64 ms
4,688 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct SegTreeAll {
	std::vector<bool> data;
	int n;
	SegTreeAll (int n_) {
		for (n = 1; n < n_; n <<= 1);
		data.resize(n << 1);
		for (int i = n_; i < n; i++) data[i + n] = true;
		for (int i = n - 1; i; i--) data[i] = data[i << 1] && data[i << 1 | 1];
	}
	void set(int i, int val) {
		for (data[i += n] = val; i >>= 1; ) data[i] = data[i << 1] && data[i << 1 | 1];
	}
	bool all(int l, int r) {
		int res = true;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) res &= data[--r];
			if (l & 1) res &= data[l++];
		}
		return res;
	}
};

int main() {
	int n = ri(), x = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	int64_t sum[n + 1];
	sum[0] = 0;
	for (int i = 0; i < n; i++) sum[i + 1] = a[i] + sum[i];
	
	int left[n + 1], right[n + 1];
	for (int i = 0; i <= n; i++) {
		left[i] = std::lower_bound(sum, sum + n + 1, sum[i] - x) - sum;
		right[i] = std::upper_bound(sum, sum + n + 1, sum[i] + x) - sum - 1;
	}
	
	std::vector<SegTreeAll> r0(n + 1, SegTreeAll(n + 1));
	std::vector<SegTreeAll> r1(n + 1, SegTreeAll(n + 1));
	
	bool dp[n + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i <= n; i++) {
		dp[i][i] = true;
		r0[i].set(i, true);
		r1[i].set(i, true);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j + i <= n; j++) {
			int k = j + i;
			dp[j][k] = false;
			// dp[j][k][?]
			// eat left -> dp[j + 1, right[j]][k]
			if (j < right[j] && !r1[k].all(j + 1, right[j] + 1)) {
				dp[j][k] = true;
			}
			// eat right -> dp[j][[left[k], k)]
			if (left[k] < k && !r0[j].all(left[k], k)) {
				dp[j][k] = true;
			}
			r0[j].set(k, dp[j][k]);
			r1[k].set(j, dp[j][k]);
		}
	}
	/*
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			std::cerr << i << "," << j << " : " << dp[i][j][0] << "," << dp[i][j][1] << std::endl;
		}
	}*/
	std::cout << (dp[0][n] ? "A" : "B") << std::endl;
	return 0;
}
0