結果

問題 No.973 余興
ユーザー betrue12betrue12
提出日時 2020-01-17 22:55:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,961 ms / 4,000 ms
コード長 2,026 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 206,776 KB
実行使用メモリ 199,488 KB
最終ジャッジ日時 2023-09-08 06:20:34
合計ジャッジ時間 61,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,782 ms
199,244 KB
testcase_01 AC 1,732 ms
199,264 KB
testcase_02 AC 1,721 ms
199,140 KB
testcase_03 AC 1,851 ms
198,964 KB
testcase_04 AC 1,726 ms
199,488 KB
testcase_05 AC 1,740 ms
199,244 KB
testcase_06 AC 1,722 ms
199,212 KB
testcase_07 AC 1,961 ms
199,016 KB
testcase_08 AC 1,788 ms
198,332 KB
testcase_09 AC 1,733 ms
199,248 KB
testcase_10 AC 1,704 ms
191,452 KB
testcase_11 AC 507 ms
74,060 KB
testcase_12 AC 514 ms
74,148 KB
testcase_13 AC 499 ms
73,524 KB
testcase_14 AC 509 ms
73,604 KB
testcase_15 AC 45 ms
11,524 KB
testcase_16 AC 46 ms
11,724 KB
testcase_17 AC 26 ms
8,492 KB
testcase_18 AC 35 ms
10,032 KB
testcase_19 AC 36 ms
9,956 KB
testcase_20 AC 26 ms
8,412 KB
testcase_21 AC 44 ms
11,632 KB
testcase_22 AC 45 ms
11,508 KB
testcase_23 AC 35 ms
10,040 KB
testcase_24 AC 37 ms
9,856 KB
testcase_25 AC 17 ms
6,428 KB
testcase_26 AC 27 ms
8,452 KB
testcase_27 AC 54 ms
12,840 KB
testcase_28 AC 36 ms
9,952 KB
testcase_29 AC 34 ms
9,972 KB
testcase_30 AC 1,738 ms
199,288 KB
testcase_31 AC 1,706 ms
199,184 KB
testcase_32 AC 1,756 ms
199,248 KB
testcase_33 AC 1,744 ms
199,244 KB
testcase_34 AC 1,677 ms
198,524 KB
testcase_35 AC 1,673 ms
199,384 KB
testcase_36 AC 1,696 ms
194,012 KB
testcase_37 AC 1,692 ms
193,940 KB
testcase_38 AC 1,668 ms
198,628 KB
testcase_39 AC 1,676 ms
198,852 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 1,705 ms
199,348 KB
testcase_47 AC 1,705 ms
199,204 KB
testcase_48 AC 1,631 ms
199,204 KB
testcase_49 AC 1,490 ms
183,844 KB
testcase_50 AC 1,693 ms
197,772 KB
testcase_51 AC 1,648 ms
199,356 KB
testcase_52 AC 1,728 ms
199,192 KB
testcase_53 AC 1,654 ms
195,832 KB
testcase_54 AC 1,731 ms
199,288 KB
testcase_55 AC 1,639 ms
199,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        if(x < 0) return -1;
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N, X;
    cin >> N >> X;
    vector<int64_t> A(N), S(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        S[i+1] = S[i] + A[i];
    }
    vector<int> lnxt(N), rnxt(N);
    int ng = 0;
    for(int l=0; l<N; l++){
        while(ng <= N && S[ng]-S[l] <= X) ng++;
        lnxt[l] = ng-1;
    }
    ng = N-1;
    for(int r=N-1; r>=0; r--){
        while(ng >= 0 && S[r+1]-S[ng] <= X) ng--;
        rnxt[r] = ng;
    }

    BIT<int> bit_L2R[5000], bit_R2L[5000];
    for(int i=0; i<N; i++){
        bit_L2R[i].initialize(N);
        bit_R2L[i].initialize(N);
        bit_L2R[i].plus(i, 1);
        bit_R2L[i].plus(i, 1);
    }
    for(int d=1; d<N; d++) for(int l=0; l+d<N; l++){
        int r = l+d;
        int lose = 1;
        if(bit_R2L[r].sum_between(l+1, min(lnxt[l], r))) lose = 0;
        if(bit_L2R[l].sum_between(max(l, rnxt[r]), r-1)) lose = 0;
        if(lose){
            bit_L2R[l].plus(r, 1);
            bit_R2L[r].plus(l, 1);
        }
    }
    int first_lose = bit_L2R[0].sum_between(N-1, N-1);
    cout << (first_lose ? "B" : "A") << endl;
    return 0;
}
0