結果

問題 No.973 余興
ユーザー shibh308shibh308
提出日時 2019-12-06 00:14:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,018 ms / 4,000 ms
コード長 2,417 bytes
コンパイル時間 3,084 ms
コンパイル使用メモリ 221,116 KB
実行使用メモリ 199,060 KB
最終ジャッジ日時 2023-08-22 20:07:33
合計ジャッジ時間 66,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,737 ms
199,016 KB
testcase_01 AC 1,767 ms
198,960 KB
testcase_02 AC 1,738 ms
199,016 KB
testcase_03 AC 1,778 ms
198,596 KB
testcase_04 AC 1,742 ms
198,960 KB
testcase_05 AC 1,759 ms
199,016 KB
testcase_06 AC 1,748 ms
198,920 KB
testcase_07 AC 1,764 ms
198,664 KB
testcase_08 AC 1,766 ms
198,088 KB
testcase_09 AC 1,770 ms
198,964 KB
testcase_10 AC 1,688 ms
191,064 KB
testcase_11 AC 599 ms
73,520 KB
testcase_12 AC 606 ms
73,564 KB
testcase_13 AC 592 ms
73,076 KB
testcase_14 AC 579 ms
72,956 KB
testcase_15 AC 44 ms
11,336 KB
testcase_16 AC 44 ms
11,524 KB
testcase_17 AC 26 ms
8,296 KB
testcase_18 AC 34 ms
9,788 KB
testcase_19 AC 34 ms
9,828 KB
testcase_20 AC 25 ms
8,164 KB
testcase_21 AC 43 ms
11,248 KB
testcase_22 AC 43 ms
11,276 KB
testcase_23 AC 35 ms
9,784 KB
testcase_24 AC 34 ms
9,668 KB
testcase_25 AC 16 ms
6,276 KB
testcase_26 AC 26 ms
8,216 KB
testcase_27 AC 52 ms
12,264 KB
testcase_28 AC 34 ms
9,800 KB
testcase_29 AC 33 ms
9,652 KB
testcase_30 AC 1,883 ms
199,028 KB
testcase_31 AC 1,879 ms
198,912 KB
testcase_32 AC 1,891 ms
198,960 KB
testcase_33 AC 1,879 ms
198,768 KB
testcase_34 AC 1,866 ms
197,924 KB
testcase_35 AC 1,878 ms
198,908 KB
testcase_36 AC 1,802 ms
193,596 KB
testcase_37 AC 1,843 ms
193,888 KB
testcase_38 AC 1,868 ms
198,232 KB
testcase_39 AC 1,858 ms
198,432 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1,900 ms
198,964 KB
testcase_47 AC 1,818 ms
199,024 KB
testcase_48 AC 1,847 ms
199,016 KB
testcase_49 AC 1,755 ms
183,784 KB
testcase_50 AC 1,858 ms
197,336 KB
testcase_51 AC 1,847 ms
198,924 KB
testcase_52 AC 1,910 ms
199,020 KB
testcase_53 AC 1,855 ms
195,448 KB
testcase_54 AC 2,018 ms
199,060 KB
testcase_55 AC 1,886 ms
198,924 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& w : v)
        cin >> w;

    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] + x);
        int idx = distance(r.begin(), it);
        nex[i] = min(idx, n);
        auto it2 = lower_bound(r.begin(), r.end(), r[i + 1] - x);
        idx = distance(r.begin(), it2);
        prev[i] = max(0, idx - 1);
    }
    /*
    for(auto& x : nex)
        cout << x << " ";
    cout << endl;
    for(auto& x : prev)
        cout << x << " ";
    cout << endl;
     */

    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 << ",[" << max(i, prev[j]) << "," << j - 1 << "]]  : ";
            cout << "[[" << i + 1 << "," << min(nex[j], j + 1) - 1 << "]," << j << "]  : ";
            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