結果

問題 No.973 余興
ユーザー drken1215drken1215
提出日時 2020-01-18 20:23:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,854 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 80,756 KB
実行使用メモリ 101,604 KB
最終ジャッジ日時 2023-09-10 11:23:25
合計ジャッジ時間 68,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,628 ms
101,200 KB
testcase_01 AC 1,667 ms
101,368 KB
testcase_02 AC 1,647 ms
101,208 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1,628 ms
101,264 KB
testcase_07 WA -
testcase_08 AC 1,644 ms
101,148 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 33 ms
6,900 KB
testcase_17 AC 21 ms
5,896 KB
testcase_18 WA -
testcase_19 AC 27 ms
6,276 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 34 ms
7,104 KB
testcase_23 WA -
testcase_24 AC 27 ms
6,108 KB
testcase_25 AC 13 ms
4,380 KB
testcase_26 AC 21 ms
5,320 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 28 ms
6,104 KB
testcase_30 WA -
testcase_31 AC 2,179 ms
101,408 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2,155 ms
100,944 KB
testcase_35 WA -
testcase_36 AC 2,103 ms
98,612 KB
testcase_37 AC 2,104 ms
98,728 KB
testcase_38 WA -
testcase_39 AC 2,153 ms
100,936 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 2,115 ms
101,352 KB
testcase_48 WA -
testcase_49 AC 1,875 ms
93,748 KB
testcase_50 WA -
testcase_51 AC 2,085 ms
101,392 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }


template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int N;
long long X;
vector<long long> a, s;
vector<int> l2r, r2l;

bool solve() {
    l2r.assign(N+1, -1), r2l.assign(N+1, -1);
    int r = 0;
    for (int l = 0; l < N; ++l) {
        while (r < N && s[r + 1] - s[l] <= X) {
            ++r;
            r2l[r] = l;
        }
        l2r[l] = r;
    }
    //COUT(l2r); COUT(r2l);

    vector<BIT<int> > dp(N+5, BIT<int>(N+5));
    for (int l = 0; l <= N; ++l) dp[l].add(l+1, 1);
    for (int bet = 1; bet <= N; ++bet) {
        for (int l = 0; l+bet <= N; ++l) {
            int r = l+bet;

            /*
            bool win = false;
            for (int l2 = l+1; l2 <= r; ++l2) {
                if (s[l2] - s[l] <= X && gote[r].sum(l2+1, l2+2) == 0) {
                    win = true;
                }
            }
            if (win) sente[l].add(r+1, 1);

            win = false;
            for (int r2 = l; r2 <= r-1; ++r2) {
                if (s[r] - s[r2] <= X && sente[l].sum(r2+1, r2+2) == 0) {
                    win = true;
                }
            }
            if (win) gote[r].add(l+1, 1);
            */
            
            // l+1, ..., min(l2r[l], r) に「負け」があれば OK
            int mi = min(l2r[l], r);
            int tmp = (mi-l) - dp[r].sum(l+2, mi+2);

            //cout << l << ", " << r << ": " << make_pair(l+1, min(l2r[l], r)) << endl;
            
            if (tmp) dp[l].add(r+1, 1);

            // max(l, r2l[r]), ..., r-1 に「負け」があれば OK
            int ma = max(l, r2l[r]);
            tmp = (r-ma) - dp[l].sum(ma+1, r+1);
            if (tmp) dp[r].add(l+1, 1);

            //cout << l << ", " << r << ": " << (dp[l].sum(r+1, r+2) ? "win" : "lose") << endl;
            
        }
    }

    /*
    for (int l = 0; l <= N; ++l) {
        COUT(l);
        cout << "sente: ";
        sente[l].print();
        cout << "gote:  ";
        gote[l].print();
    }
    */
    
    return dp[0].sum(N+1, N+2);
}

int main() {
    while (cin >> N >> X) {
        a.resize(N); s.assign(N+1, 0);
        for (int i = 0; i < N; ++i) cin >> a[i], s[i+1] = s[i] + a[i];
        if (solve()) cout << "A" << endl;
        else cout << "B" << endl;
    }
}
0