結果

問題 No.973 余興
ユーザー drken1215drken1215
提出日時 2020-01-18 19:25:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,509 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 80,756 KB
実行使用メモリ 395,372 KB
最終ジャッジ日時 2023-09-10 10:03:28
合計ジャッジ時間 86,101 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,067 ms
395,104 KB
testcase_01 AC 2,096 ms
395,064 KB
testcase_02 AC 2,132 ms
394,796 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2,140 ms
394,900 KB
testcase_07 WA -
testcase_08 AC 2,154 ms
393,476 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 52 ms
19,372 KB
testcase_17 AC 31 ms
13,040 KB
testcase_18 WA -
testcase_19 AC 40 ms
16,240 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 52 ms
18,896 KB
testcase_23 WA -
testcase_24 AC 39 ms
15,792 KB
testcase_25 AC 17 ms
8,900 KB
testcase_26 AC 30 ms
12,896 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 41 ms
15,768 KB
testcase_30 WA -
testcase_31 AC 2,722 ms
395,172 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2,684 ms
393,316 KB
testcase_35 WA -
testcase_36 AC 2,530 ms
384,448 KB
testcase_37 AC 2,571 ms
384,556 KB
testcase_38 WA -
testcase_39 AC 2,672 ms
394,228 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 2,548 ms
394,800 KB
testcase_48 WA -
testcase_49 AC 2,448 ms
364,380 KB
testcase_50 WA -
testcase_51 AC 2,658 ms
395,064 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<long long> > sente(N+5, BIT<long long>(N+5));
    vector<BIT<long long> > gote(N+5, BIT<long long>(N+5));
    for (int l = 0; l <= N; ++l) sente[l].add(l+1, 1);
    for (int r = 0; r <= N; ++r) gote[r].add(r+1, 1);
    for (int bet = 1; bet <= N; ++bet) {
        for (int l = 0; l+bet <= N; ++l) {
            int r = l + bet;

            // l+1, ..., min(l2r[l], r) に「負け」があれば OK
            long long mi = min(l2r[l], r);
            long long tmp = (mi-l) - gote[r].sum(l+2, mi+2);

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

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

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

    /*
    for (int l = 0; l <= N; ++l) {
        COUT(l);
        cout << "sente: ";
        sente[l].print();
        cout << "gote:  ";
        gote[l].print();
    }
    */
    
    return sente[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