結果
問題 | No.973 余興 |
ユーザー | fine |
提出日時 | 2020-01-17 22:41:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 6,378 bytes |
コンパイル時間 | 1,721 ms |
コンパイル使用メモリ | 176,892 KB |
実行使用メモリ | 324,480 KB |
最終ジャッジ日時 | 2024-06-25 22:32:06 |
合計ジャッジ時間 | 12,528 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | AC | 492 ms
99,840 KB |
testcase_12 | AC | 622 ms
99,968 KB |
testcase_13 | AC | 490 ms
99,712 KB |
testcase_14 | AC | 449 ms
99,584 KB |
testcase_15 | AC | 86 ms
11,392 KB |
testcase_16 | AC | 88 ms
11,392 KB |
testcase_17 | AC | 51 ms
9,728 KB |
testcase_18 | AC | 65 ms
10,752 KB |
testcase_19 | AC | 67 ms
10,752 KB |
testcase_20 | AC | 50 ms
9,600 KB |
testcase_21 | AC | 85 ms
11,392 KB |
testcase_22 | AC | 85 ms
11,520 KB |
testcase_23 | AC | 68 ms
10,624 KB |
testcase_24 | AC | 67 ms
10,752 KB |
testcase_25 | AC | 29 ms
8,192 KB |
testcase_26 | AC | 49 ms
9,600 KB |
testcase_27 | AC | 137 ms
20,736 KB |
testcase_28 | AC | 65 ms
10,496 KB |
testcase_29 | AC | 63 ms
10,624 KB |
testcase_30 | AC | 1,641 ms
324,224 KB |
testcase_31 | AC | 1,616 ms
324,352 KB |
testcase_32 | AC | 1,641 ms
324,352 KB |
testcase_33 | AC | 1,654 ms
324,224 KB |
testcase_34 | AC | 1,622 ms
323,584 KB |
testcase_35 | AC | 1,646 ms
324,352 KB |
testcase_36 | AC | 1,594 ms
320,000 KB |
testcase_37 | AC | 1,596 ms
320,128 KB |
testcase_38 | AC | 1,646 ms
323,712 KB |
testcase_39 | AC | 1,643 ms
323,840 KB |
testcase_40 | AC | 3 ms
6,944 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,948 KB |
testcase_43 | AC | 2 ms
6,948 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 4 ms
6,948 KB |
testcase_46 | AC | 1,656 ms
324,480 KB |
testcase_47 | AC | 1,669 ms
324,224 KB |
testcase_48 | AC | 1,651 ms
324,480 KB |
testcase_49 | AC | 1,577 ms
311,552 KB |
testcase_50 | AC | 1,672 ms
323,072 KB |
testcase_51 | AC | 1,720 ms
324,224 KB |
testcase_52 | AC | 1,712 ms
324,352 KB |
testcase_53 | AC | 1,821 ms
321,408 KB |
testcase_54 | AC | 1,716 ms
324,224 KB |
testcase_55 | AC | 1,688 ms
324,352 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; // 参考: http://kazuma8128.hatenablog.com/entry/2017/12/29/081929 template <class MonoidOp> struct LazySegmentTree { using Tm = typename MonoidOp::Tm; using To = typename MonoidOp::To; int n; int h; vector<Tm> data; vector<To> lazy; LazySegmentTree() {} LazySegmentTree(int size, Tm initial_data_value = MonoidOp::unit()) { n = 1; h = 0; while (n < size) { h++; n <<= 1; } data.assign((n << 1), initial_data_value); lazy.assign((n << 1), MonoidOp::op_unit()); if (initial_data_value != MonoidOp::unit()) { for (int i = n - 1; i > 0; i--) data[i] = MonoidOp::merge(data[(i << 1)], data[(i << 1) + 1]); } } LazySegmentTree(const vector<Tm>& v) { int size = v.size(); n = 1; h = 0; while (n < size) { h++; n <<= 1; } data.assign((n << 1), MonoidOp::unit()); lazy.assign((n << 1), MonoidOp::op_unit()); for (int i = 0; i < size; i++) data[i + n] = v[i]; for (int i = n - 1; i > 0; i--) data[i] = MonoidOp::merge(data[(i << 1)], data[(i << 1) + 1]); } // https://komiyam.hatenadiary.org/entry/20131202/1385992406 inline int getSegLen(int k) { return n / (1 << (31 - __builtin_clz(k))); } Tm getLeaf(int k) { return query(k, k + 1); } void push(int k) { if (lazy[k] == MonoidOp::op_unit()) return; int seg_len = getSegLen(k); data[k] = MonoidOp::apply(data[k], lazy[k], seg_len); if (seg_len > 1) { lazy[(k << 1)] = MonoidOp::op_merge(lazy[(k << 1)], lazy[k]); lazy[(k << 1) + 1] = MonoidOp::op_merge(lazy[(k << 1) + 1], lazy[k]); } lazy[k] = MonoidOp::op_unit(); } void update(int k) { Tm vl = MonoidOp::apply(data[(k << 1)], lazy[(k << 1)], getSegLen(k << 1)); Tm vr = MonoidOp::apply(data[(k << 1) + 1], lazy[(k << 1) + 1], getSegLen((k << 1) + 1)); data[k] = MonoidOp::merge(vl, vr); } //区間[a, b)に対する更新 void update(int a, int b, To x) { a += n, b += n - 1; for (int i = h; i > 0; i--) { push(a >> i); push(b >> i); } for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) lazy[l] = MonoidOp::op_merge(lazy[l], x), l++; if (r & 1) --r, lazy[r] = MonoidOp::op_merge(lazy[r], x); } while (a >>= 1, b >>= 1, a) { if (lazy[a] == MonoidOp::op_unit()) update(a); if (lazy[b] == MonoidOp::op_unit()) update(b); } } //区間[a, b)に対するクエリに答える Tm query(int a, int b) { a += n, b += n - 1; for (int i = h; i > 0; i--) { push(a >> i); push(b >> i); } Tm vl = MonoidOp::unit(), vr = MonoidOp::unit(); for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) { vl = MonoidOp::merge(vl, MonoidOp::apply(data[l], lazy[l], getSegLen(l))); l++; } if (r & 1) { --r; vr = MonoidOp::merge(MonoidOp::apply(data[r], lazy[r], getSegLen(r)), vr); } } return MonoidOp::merge(vl, vr); } }; // 以下、MonoidOpの例 template<class U = ll, class V = U> struct RangeSumAdd { using Tm = U; using To = V; static Tm merge(Tm x, Tm y) { return x + y; } static To op_merge(To x, To y) { return x + y; } static Tm apply(Tm vm, To vo, int seg_len) { return vm + vo * seg_len; } static constexpr Tm unit() { return Tm(0); } static constexpr To op_unit() { return To(0); } }; template<class U = ll, class V = U> struct RangeMinUpdate { using Tm = U; using To = V; static Tm merge(Tm x, Tm y) { return min(x, y); } static To op_merge(To x, To y) { return y; } static Tm apply(Tm vm, To vo, int seg_len) { return vo == op_unit() ? vm : vo; } static constexpr Tm unit() { return numeric_limits<Tm>::max(); } static constexpr To op_unit() { return numeric_limits<To>::max(); } }; // 作用素の初期値は更新クエリで与えられる値の定義域の範囲外の値にする template<class U = ll, class V = U> struct RangeSumUpdate { using Tm = U; using To = V; static Tm merge(Tm x, Tm y) { return x + y; } static To op_merge(To x, To y) { return y; } static Tm apply(Tm vm, To vo, int seg_len) { return vo == op_unit() ? vm : vo * seg_len; } static constexpr Tm unit() { return Tm(0); } static constexpr To op_unit() { return numeric_limits<To>::min(); } }; // 初期値 != 単位元 の場合に注意 template<class U = ll, class V = U> struct RangeMinAdd { using Tm = U; using To = V; static Tm merge(Tm x, Tm y) { return min(x, y); } static To op_merge(To x, To y) { return x + y; } static Tm apply(Tm vm, To vo, int seg_len) { return vm + vo; } static constexpr Tm unit() { return numeric_limits<Tm>::max(); } static constexpr To op_unit() { return To(0); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; ll x; cin >> n >> x; vector<ll> a(n), sum(n + 1, 0); using Seg = LazySegmentTree< RangeMinUpdate<char> >; vector<Seg> st_row(n + 1, Seg(n + 1, false)), st_col(n + 1, Seg(n + 1, false)); for (int i = 0; i < n; ++i) { cin >> a[i]; sum[i + 1] = sum[i] + a[i]; st_row[i].update(i, i + 1, 1); st_col[i].update(i, i + 1, 1); } for (int d = 1; d < n; ++d) { for (int i = 0; i <= n - d; ++i) { if (st_row[i].query(i + d, i + d + 1) || st_col[i + d].query(i, i + 1)) continue; { int idx = lower_bound(sum.begin(), sum.begin() + i, sum[i] - x) - sum.begin(); if (idx < i) st_col[i + d].update(idx, i, true); } { int idx = upper_bound(sum.begin() + i + d, sum.end(), x + sum[i + d]) - sum.begin(); if (i + d < idx) st_row[i].update(i + d, idx, true); } } } cout << ((st_row[0].query(n, n + 1) || st_col[n].query(0, 1)) ? "A" : "B") << "\n"; return 0; }