結果

問題 No.973 余興
ユーザー mugen_1337mugen_1337
提出日時 2021-04-14 17:19:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 779 ms / 4,000 ms
コード長 2,659 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 206,320 KB
実行使用メモリ 199,004 KB
最終ジャッジ日時 2023-09-13 06:51:41
合計ジャッジ時間 27,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 631 ms
198,876 KB
testcase_01 AC 622 ms
198,872 KB
testcase_02 AC 625 ms
198,868 KB
testcase_03 AC 634 ms
198,936 KB
testcase_04 AC 624 ms
198,996 KB
testcase_05 AC 626 ms
198,924 KB
testcase_06 AC 627 ms
198,872 KB
testcase_07 AC 619 ms
198,924 KB
testcase_08 AC 627 ms
198,520 KB
testcase_09 AC 637 ms
198,864 KB
testcase_10 AC 599 ms
191,276 KB
testcase_11 AC 230 ms
73,736 KB
testcase_12 AC 227 ms
73,728 KB
testcase_13 AC 226 ms
73,324 KB
testcase_14 AC 228 ms
73,268 KB
testcase_15 AC 17 ms
10,980 KB
testcase_16 AC 18 ms
11,164 KB
testcase_17 AC 10 ms
7,992 KB
testcase_18 AC 13 ms
9,440 KB
testcase_19 AC 13 ms
9,320 KB
testcase_20 AC 10 ms
7,812 KB
testcase_21 AC 17 ms
11,032 KB
testcase_22 AC 17 ms
10,972 KB
testcase_23 AC 13 ms
9,388 KB
testcase_24 AC 12 ms
9,444 KB
testcase_25 AC 7 ms
5,940 KB
testcase_26 AC 10 ms
7,780 KB
testcase_27 AC 21 ms
12,276 KB
testcase_28 AC 13 ms
9,444 KB
testcase_29 AC 13 ms
9,312 KB
testcase_30 AC 757 ms
198,864 KB
testcase_31 AC 755 ms
198,920 KB
testcase_32 AC 755 ms
198,920 KB
testcase_33 AC 745 ms
199,004 KB
testcase_34 AC 769 ms
198,080 KB
testcase_35 AC 767 ms
198,932 KB
testcase_36 AC 757 ms
193,856 KB
testcase_37 AC 755 ms
193,852 KB
testcase_38 AC 779 ms
198,340 KB
testcase_39 AC 773 ms
198,820 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 606 ms
198,924 KB
testcase_47 AC 614 ms
198,936 KB
testcase_48 AC 611 ms
198,868 KB
testcase_49 AC 563 ms
183,604 KB
testcase_50 AC 599 ms
197,616 KB
testcase_51 AC 620 ms
198,996 KB
testcase_52 AC 777 ms
198,940 KB
testcase_53 AC 760 ms
195,568 KB
testcase_54 AC 775 ms
198,936 KB
testcase_55 AC 774 ms
198,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 998244353
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}



signed main(){
    int n;ll x;cin>>n>>x;
    vector<ll> v(n);
    cin>>v;
    vector<int> t_l(n),t_r(n);// can take [i, t_l[i]], [t_r[i], i]
    
    vector<ll> s(n);
    s[0]=v[0];
    for(int i=1;i<n;i++) s[i]=s[i-1]+v[i];

    for(int i=0;i<n;i++){
        {
            ll offset=(i?s[i-1]:0);
            int r=lower_bound(ALL(s),offset+x+1)-begin(s);
            t_l[i]=r-1;
        }
        {
            ll sum=0;
            int j;
            for(j=i;j>=0;j--){
                sum+=v[j];
                if(sum>x) break;
            }
            t_r[i]=j+1;
        }
    }


    for(int i=0;i<n;i++){
        ll sum=0;
        for(int j=i;j<=t_l[i];j++) sum+=v[j];
        assert(sum<=x);
    }

    for(int i=0;i<n;i++){
        ll sum=0;
        for(int j=t_r[i];j<=i;j++) sum+=v[j];
        // assert(sum<=x);
    }

    vector<vector<int>> L(n+2,vector<int>(n+2,0)),R(n+2,vector<int>(n+2,0));
    rep(i,n) L[i][i]=1,R[i][i]=1;

    auto getL=[&](int R,int l,int r){
        int ret=L[l][R];
        if(r+1<=n) ret-=L[r+1][R];
        return ret;
    };
    auto getR=[&](int L,int l,int r){
        int ret=R[L][r];
        if(l) ret-=R[L][l-1];
        return ret;
    };

    bool res=false;
    for(int w=2;w<=n;w++){
        for(int l=0;l+w<=n;l++){
            int r=l+w-1;

            bool win=false;
            int a=t_l[l];// can eat [l,a]
            int b=t_r[r];// [b,r]

            if(getL(r,l+1,a+1)) win=true;
            if(getR(l,b-1,r-1)) win=true;

            L[l][r]=L[l+1][r];
            R[l][r]=R[l][r-1];
            if(!win){
                L[l][r]++;
                R[l][r]++;
            }
            if(l==0 and r==n-1) res=win;
        }
    }
    cout<<("BA"[res])<<endl;
    return 0;
}
0