結果

問題 No.973 余興
ユーザー kimiyukikimiyuki
提出日時 2020-01-18 06:50:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,295 ms / 4,000 ms
コード長 2,140 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 207,080 KB
実行使用メモリ 101,540 KB
最終ジャッジ日時 2023-09-09 03:56:40
合計ジャッジ時間 44,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,105 ms
101,540 KB
testcase_01 AC 1,120 ms
101,196 KB
testcase_02 AC 1,109 ms
101,256 KB
testcase_03 AC 1,123 ms
101,248 KB
testcase_04 AC 1,114 ms
101,536 KB
testcase_05 AC 1,115 ms
101,352 KB
testcase_06 AC 1,100 ms
101,540 KB
testcase_07 AC 1,109 ms
101,316 KB
testcase_08 AC 1,102 ms
100,660 KB
testcase_09 AC 1,117 ms
101,212 KB
testcase_10 AC 1,068 ms
97,280 KB
testcase_11 AC 349 ms
38,524 KB
testcase_12 AC 349 ms
38,480 KB
testcase_13 AC 346 ms
38,100 KB
testcase_14 AC 342 ms
38,164 KB
testcase_15 AC 31 ms
6,976 KB
testcase_16 AC 32 ms
7,356 KB
testcase_17 AC 20 ms
5,480 KB
testcase_18 AC 25 ms
6,176 KB
testcase_19 AC 25 ms
6,188 KB
testcase_20 AC 18 ms
5,508 KB
testcase_21 AC 31 ms
6,916 KB
testcase_22 AC 31 ms
7,096 KB
testcase_23 AC 25 ms
6,276 KB
testcase_24 AC 24 ms
6,152 KB
testcase_25 AC 11 ms
4,672 KB
testcase_26 AC 18 ms
5,456 KB
testcase_27 AC 36 ms
7,756 KB
testcase_28 AC 25 ms
6,152 KB
testcase_29 AC 24 ms
6,124 KB
testcase_30 AC 1,257 ms
101,196 KB
testcase_31 AC 1,220 ms
101,224 KB
testcase_32 AC 1,254 ms
101,384 KB
testcase_33 AC 1,237 ms
101,300 KB
testcase_34 AC 1,255 ms
100,636 KB
testcase_35 AC 1,238 ms
101,228 KB
testcase_36 AC 1,210 ms
98,576 KB
testcase_37 AC 1,212 ms
98,532 KB
testcase_38 AC 1,268 ms
100,992 KB
testcase_39 AC 1,240 ms
100,904 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1,238 ms
101,288 KB
testcase_47 AC 1,232 ms
101,168 KB
testcase_48 AC 1,295 ms
101,200 KB
testcase_49 AC 1,097 ms
93,592 KB
testcase_50 AC 1,226 ms
100,500 KB
testcase_51 AC 1,214 ms
101,504 KB
testcase_52 AC 1,268 ms
101,276 KB
testcase_53 AC 1,212 ms
99,792 KB
testcase_54 AC 1,263 ms
101,300 KB
testcase_55 AC 1,236 ms
101,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)
using namespace std;
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; }

/**
 * @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;
}


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, n + 2, int16_t());
    auto vr = make_table(n + 1, n + 2, int16_t());
    REP (len, n + 1) REP (l, n - len + 1) {
        int r = l + len;
        bool cur;
        if (len == 0) {
            cur = true;
        } else {
           int m1 = binsearch(l + 1, r, [&](int m1) {
               return acc[m1] - acc[l] > x;
           });
           int m2 = binsearch(l, r, [&](int m2) {
               return acc[r] - acc[m2] <= x;
           });
           cur = vr[r][l + 1] - vr[r][m1] + hr[l][r] - hr[l][m2];
        }
        hr[l][r + 1] = hr[l][r] + not cur;
        vr[r][l] = vr[r][l + 1] + not cur;
    }
    return not (hr[0][n + 1] - hr[0][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;
}
0