結果

問題 No.973 余興
ユーザー betrue12betrue12
提出日時 2020-01-17 22:50:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,024 bytes
コンパイル時間 2,624 ms
コンパイル使用メモリ 206,428 KB
実行使用メモリ 199,456 KB
最終ジャッジ日時 2023-09-08 06:00:59
合計ジャッジ時間 63,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,758 ms
199,152 KB
testcase_01 AC 1,764 ms
199,348 KB
testcase_02 AC 1,762 ms
199,184 KB
testcase_03 AC 1,907 ms
198,932 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1,886 ms
199,200 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 498 ms
74,188 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 476 ms
73,492 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 27 ms
8,648 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 42 ms
11,600 KB
testcase_23 AC 34 ms
10,088 KB
testcase_24 AC 35 ms
10,000 KB
testcase_25 AC 15 ms
6,500 KB
testcase_26 AC 26 ms
8,372 KB
testcase_27 AC 50 ms
12,736 KB
testcase_28 WA -
testcase_29 AC 32 ms
9,936 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1,714 ms
199,328 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1,727 ms
198,644 KB
testcase_39 WA -
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 WA -
testcase_44 AC 2 ms
4,380 KB
testcase_45 WA -
testcase_46 AC 1,691 ms
199,272 KB
testcase_47 WA -
testcase_48 AC 1,739 ms
199,172 KB
testcase_49 AC 1,575 ms
183,944 KB
testcase_50 AC 1,694 ms
197,808 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1,618 ms
195,808 KB
testcase_54 AC 1,703 ms
199,160 KB
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

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