結果

問題 No.973 余興
ユーザー QCFiumQCFium
提出日時 2020-01-17 22:53:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,059 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 175,604 KB
実行使用メモリ 37,704 KB
最終ジャッジ日時 2023-09-08 06:15:35
合計ジャッジ時間 129,630 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,116 ms
37,648 KB
testcase_01 AC 3,169 ms
37,424 KB
testcase_02 AC 3,047 ms
37,152 KB
testcase_03 AC 3,259 ms
37,224 KB
testcase_04 AC 3,087 ms
37,444 KB
testcase_05 AC 3,118 ms
37,172 KB
testcase_06 AC 3,220 ms
37,308 KB
testcase_07 AC 3,062 ms
37,324 KB
testcase_08 AC 3,043 ms
37,184 KB
testcase_09 AC 3,163 ms
37,500 KB
testcase_10 AC 2,912 ms
35,864 KB
testcase_11 AC 1,292 ms
15,636 KB
testcase_12 AC 1,318 ms
15,620 KB
testcase_13 AC 1,283 ms
15,708 KB
testcase_14 AC 1,265 ms
15,540 KB
testcase_15 AC 89 ms
5,004 KB
testcase_16 AC 89 ms
4,908 KB
testcase_17 AC 56 ms
4,472 KB
testcase_18 AC 70 ms
4,696 KB
testcase_19 AC 72 ms
4,616 KB
testcase_20 AC 54 ms
4,516 KB
testcase_21 AC 87 ms
4,944 KB
testcase_22 AC 88 ms
4,856 KB
testcase_23 AC 72 ms
4,800 KB
testcase_24 AC 72 ms
4,648 KB
testcase_25 AC 32 ms
4,376 KB
testcase_26 AC 54 ms
4,408 KB
testcase_27 AC 105 ms
5,228 KB
testcase_28 AC 70 ms
4,604 KB
testcase_29 AC 69 ms
4,692 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 3,965 ms
37,704 KB
testcase_47 TLE -
testcase_48 TLE -
testcase_49 AC 3,640 ms
34,616 KB
testcase_50 AC 3,954 ms
37,184 KB
testcase_51 AC 3,946 ms
37,204 KB
testcase_52 TLE -
testcase_53 AC 3,866 ms
36,756 KB
testcase_54 TLE -
testcase_55 AC 3,947 ms
37,484 KB
権限があれば一括ダウンロードができます

ソースコード

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(1));
	std::vector<SegTreeAll> r1(n + 1, SegTreeAll(1));
	for (int i = 0; i <= n; i++) r0[i] = SegTreeAll(n - i + 1);
	for (int i = 0; i <= n; i++) r1[i] = SegTreeAll(i + 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(0, 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, std::min(k, right[j] + 1))) {
				dp[j][k] = true;
			}
			// eat right -> dp[j][[left[k], k)]
			if (left[k] < k && !r0[j].all(std::max(0, left[k] - j), k - j)) {
				dp[j][k] = true;
			}
			r0[j].set(k - j, 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;
		}
	}*/
	puts(dp[0][n] ? "A" : "B");
	return 0;
}
0