結果
| 問題 |
No.973 余興
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-18 06:10:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,330 bytes |
| コンパイル時間 | 2,309 ms |
| コンパイル使用メモリ | 205,540 KB |
| 最終ジャッジ日時 | 2025-01-08 19:53:00 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 26 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#define dump(x) cerr << #x " = " << x << endl
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> istream & operator >> (istream & in, vector<T> & xs) { REP (i, xs.size()) { in >> xs[i]; } return in; }
template <typename T> ostream & operator << (ostream & out, const vector<T> & xs) { REP (i, xs.size()) { if (i) { out << ' '; } out << xs[i]; } return out; }
/**
* @brief a segment tree / セグメント木
* @docs data_structure/segment_tree.md
* @tparam Monoid (commutativity is not required)
*/
template <class Monoid>
struct segment_tree {
typedef typename Monoid::value_type value_type;
const Monoid mon;
int n;
std::vector<value_type> a;
segment_tree() = default;
segment_tree(int n_, const Monoid & mon_ = Monoid()) : mon(mon_) {
n = 1; while (n < n_) n *= 2;
a.resize(2 * n - 1, mon.unit());
}
void point_set(int i, value_type b) { // 0-based
assert (0 <= i and i < n);
a[i + n - 1] = b;
for (i = (i + n) / 2; i > 0; i /= 2) { // 1-based
a[i - 1] = mon.mult(a[2 * i - 1], a[2 * i]);
}
}
value_type range_get(int l, int r) { // 0-based, [l, r)
assert (0 <= l and l <= r and r <= n);
value_type lacc = mon.unit(), racc = mon.unit();
for (l += n, r += n; l < r; l /= 2, r /= 2) { // 1-based loop, 2x faster than recursion
if (l % 2 == 1) lacc = mon.mult(lacc, a[(l ++) - 1]);
if (r % 2 == 1) racc = mon.mult(a[(-- r) - 1], racc);
}
return mon.mult(lacc, racc);
}
value_type point_get(int i) { // 0-based
assert (0 <= i and i < n);
return a[i + n - 1];
}
/**
* @brief a fast & semigroup-friendly version constructor
* @note $O(n)$
*/
template <class InputIterator>
segment_tree(InputIterator first, InputIterator last, const Monoid & mon_ = Monoid()) : mon(mon_) {
int size = std::distance(first, last);
n = 1; while (n < size) n *= 2;
a.resize(2 * n - 1, mon.unit());
std::copy(first, last, a.begin() + (n - 1));
unsafe_rebuild();
}
/**
* @brief update a leaf node without updating ancestors
* @note $O(1)$
*/
void unsafe_point_set(int i, value_type b) { // 0-based
assert (0 <= i and i < n);
a[i + n - 1] = b;
}
/**
* @brief re-build non-leaf nodes from leaf nodes
* @note $O(n)$
*/
void unsafe_rebuild() {
REP_R (i, n - 1) {
a[i] = mon.mult(a[2 * i + 1], a[2 * i + 2]);
}
}
};
template <class T>
struct plus_monoid {
typedef T value_type;
value_type unit() const { return value_type(); }
value_type mult(value_type a, value_type b) const { return a + b; }
};
/**
* @brief a binary search / 二分探索
* @param[in] p a monotone predicate defined on $[l, r)$
* @return $\min \lbrace x \in [l, r) \mid p(x) \rbrace$, or r if it doesn't exist
*/
template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
assert (l <= r);
-- l;
while (r - l > 1) {
int64_t m = l + (r - l) / 2;
(p(m) ? r : l) = m;
}
return r;
}
template <typename UnaryPredicate>
int64_t binsearch_max(int64_t l, int64_t r, UnaryPredicate p) {
assert (l <= r);
++ r;
while (r - l > 1) {
int64_t m = l + (r - l) / 2;
(p(m) ? l : r) = m;
}
return l;
}
bool solve(int n, int x, const vector<int64_t> & a) {
vector<int64_t> acc(n + 1);
partial_sum(ALL(a), acc.begin() + 1);
auto hr = make_table(n + 1, segment_tree<plus_monoid<int16_t> >(n + 1));
auto vr = make_table(n + 1, segment_tree<plus_monoid<int16_t> >(n + 1));
REP (len, n + 1) REP (l, n - len + 1) {
int r = l + len;
bool cur;
if (len == 0) {
cur = false;
} else {
int m1 = binsearch(l + 1, r + 1, [&](int m1) {
return acc[m1] - acc[l] > x;
});
int m2 = binsearch(l, r, [&](int m2) {
return acc[r] - acc[m2] <= x;
});
cur = hr[l].range_get(l + 1, m1) or vr[r].range_get(m2, r);
}
if (not cur) {
hr[l].point_set(r, 1);
vr[r].point_set(l, 1);
}
}
return not hr[0].point_get(n);
}
int main() {
int n, x; cin >> n >> x;
vector<int64_t> a(n); cin >> a;
cout << (solve(n, x, a) ? "A" : "B") << endl;
return 0;
}