結果

問題 No.973 余興
ユーザー QCFiumQCFium
提出日時 2020-01-17 22:52:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,046 bytes
コンパイル時間 2,700 ms
コンパイル使用メモリ 176,744 KB
実行使用メモリ 37,652 KB
最終ジャッジ日時 2023-09-08 06:06:40
合計ジャッジ時間 15,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,096 ms
37,472 KB
testcase_01 AC 3,136 ms
37,436 KB
testcase_02 AC 3,085 ms
37,256 KB
testcase_03 AC 3,042 ms
37,328 KB
testcase_04 AC 3,154 ms
37,608 KB
testcase_05 AC 3,073 ms
37,140 KB
testcase_06 AC 3,122 ms
37,372 KB
testcase_07 AC 3,127 ms
37,236 KB
testcase_08 AC 3,072 ms
37,112 KB
testcase_09 AC 3,245 ms
37,140 KB
testcase_10 AC 2,951 ms
35,920 KB
testcase_11 AC 1,339 ms
15,664 KB
testcase_12 AC 1,353 ms
15,720 KB
testcase_13 AC 1,363 ms
15,788 KB
testcase_14 AC 1,329 ms
15,716 KB
testcase_15 AC 88 ms
4,828 KB
testcase_16 AC 89 ms
5,100 KB
testcase_17 AC 58 ms
4,396 KB
testcase_18 AC 73 ms
4,732 KB
testcase_19 AC 73 ms
4,684 KB
testcase_20 AC 55 ms
4,404 KB
testcase_21 AC 92 ms
4,940 KB
testcase_22 AC 87 ms
5,044 KB
testcase_23 AC 72 ms
4,896 KB
testcase_24 AC 70 ms
4,716 KB
testcase_25 AC 33 ms
4,376 KB
testcase_26 AC 54 ms
4,380 KB
testcase_27 AC 102 ms
5,368 KB
testcase_28 AC 72 ms
4,656 KB
testcase_29 AC 71 ms
4,684 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 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 TLE -
testcase_54 TLE -
testcase_55 TLE -
権限があれば一括ダウンロードができます

ソースコード

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(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