結果

問題 No.973 余興
ユーザー shibh308shibh308
提出日時 2019-12-05 00:19:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,046 bytes
コンパイル時間 3,902 ms
コンパイル使用メモリ 223,428 KB
実行使用メモリ 199,168 KB
最終ジャッジ日時 2024-05-10 01:37:42
合計ジャッジ時間 48,406 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,755 ms
199,040 KB
testcase_01 AC 1,792 ms
199,040 KB
testcase_02 AC 1,785 ms
199,040 KB
testcase_03 AC 1,763 ms
198,912 KB
testcase_04 AC 1,747 ms
199,168 KB
testcase_05 AC 1,767 ms
199,040 KB
testcase_06 WA -
testcase_07 AC 1,766 ms
198,912 KB
testcase_08 AC 1,843 ms
198,272 KB
testcase_09 WA -
testcase_10 AC 1,698 ms
191,232 KB
testcase_11 AC 605 ms
73,856 KB
testcase_12 AC 568 ms
73,856 KB
testcase_13 AC 592 ms
73,216 KB
testcase_14 AC 560 ms
73,216 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 28 ms
8,448 KB
testcase_18 AC 36 ms
9,728 KB
testcase_19 AC 37 ms
9,856 KB
testcase_20 AC 27 ms
8,320 KB
testcase_21 AC 47 ms
11,392 KB
testcase_22 WA -
testcase_23 AC 36 ms
9,728 KB
testcase_24 AC 38 ms
9,728 KB
testcase_25 AC 17 ms
6,528 KB
testcase_26 AC 29 ms
8,320 KB
testcase_27 AC 58 ms
12,416 KB
testcase_28 AC 38 ms
9,856 KB
testcase_29 AC 36 ms
9,856 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,888 ms
198,144 KB
testcase_35 AC 1,861 ms
199,168 KB
testcase_36 AC 1,842 ms
194,048 KB
testcase_37 AC 1,904 ms
193,920 KB
testcase_38 AC 1,869 ms
198,400 KB
testcase_39 AC 1,881 ms
198,784 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 WA -
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 1,857 ms
199,168 KB
testcase_47 AC 1,735 ms
199,168 KB
testcase_48 AC 1,877 ms
199,168 KB
testcase_49 AC 1,761 ms
183,680 KB
testcase_50 AC 1,840 ms
197,632 KB
testcase_51 AC 1,819 ms
199,168 KB
testcase_52 AC 1,869 ms
199,168 KB
testcase_53 AC 1,889 ms
195,584 KB
testcase_54 AC 1,908 ms
199,040 KB
testcase_55 AC 1,906 ms
199,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

template <typename T>
struct BIT{
    vector<T> elm;
    BIT(int n, T init = T()) : elm(n + 1, init){
    }

    // [0, x)
    T sum(int x){
        T val = 0;
        for(; x > 0; x -= x & -x)
            val += elm[x];
        return val;
    }

    // [l, r)
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    void add(int x, T val){
        for(++x; x < elm.size(); x += x & -x)
            elm[x] += val;
    }
};

signed main(){
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for(auto& x : v)
        cin >> x;

    vector<i64> r(n + 1, 0);
    for(int i = 0; i < n; ++i)
        r[i + 1] = r[i] + v[i];

    vector<int> nex(n, n), prev(n, 0);
    for(int i = 0; i < n; ++i){
        auto it = upper_bound(r.begin(), r.end(), r[i + 1] + x);
        int idx = distance(r.begin(), it);
        nex[i] = idx - 1;
        auto it2 = lower_bound(r.begin(), r.end(), r[i] - x);
        idx = distance(r.begin(), it2);
        prev[i] = idx;
    }

    vector<BIT<int>> a(n, BIT<int>(n)), b(n, BIT<int>(n));

    for(int k = 1; k < n; ++k)
        for(int i = 0, j = k; j < n; ++i, ++j){
            bool f = false;
            // TODO: set len

            // dp[i][j] : dp[i][j - x, j)
            // cout << j - prev[j] << "   " << nex[i] - (i + 1) << "    ";
            f |= (a[i].sum(max(i, prev[j]), j) != (j - max(i, prev[j])));

            // dp[i][j] : dp[i, i + x][j, j)
            f |= (b[j].sum(i + 1, min(nex[i], j + 1)) != (min(nex[i], j + 1) - (i + 1)));
            if(f){
                a[i].add(j, 1);
                b[j].add(i, 1);
            }
            // cout << "[" << i << "," << j << "] -> " << (f ? "Win" : "Lose") << endl;
        }

    /*
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j)
            cout << a[i].sum(j, j + 1) << " \n"[j == n - 1];
    }
    cout << endl;
     */
    cout << (a[0].sum(n - 1, n) ? "A" : "B") << endl;
}
0