結果

問題 No.973 余興
ユーザー mugen_1337mugen_1337
提出日時 2021-04-14 17:21:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,026 ms / 4,000 ms
コード長 2,709 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 206,228 KB
実行使用メモリ 199,040 KB
最終ジャッジ日時 2023-09-13 06:53:25
合計ジャッジ時間 33,302 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 756 ms
198,976 KB
testcase_01 AC 762 ms
198,924 KB
testcase_02 AC 763 ms
198,872 KB
testcase_03 AC 763 ms
198,860 KB
testcase_04 AC 765 ms
198,884 KB
testcase_05 AC 766 ms
198,984 KB
testcase_06 AC 767 ms
198,868 KB
testcase_07 AC 768 ms
198,872 KB
testcase_08 AC 763 ms
198,088 KB
testcase_09 AC 764 ms
198,988 KB
testcase_10 AC 728 ms
191,424 KB
testcase_11 AC 310 ms
73,724 KB
testcase_12 AC 325 ms
73,728 KB
testcase_13 AC 310 ms
72,936 KB
testcase_14 AC 319 ms
73,324 KB
testcase_15 AC 19 ms
11,076 KB
testcase_16 AC 20 ms
11,164 KB
testcase_17 AC 10 ms
7,964 KB
testcase_18 AC 13 ms
9,396 KB
testcase_19 AC 13 ms
9,396 KB
testcase_20 AC 10 ms
7,856 KB
testcase_21 AC 19 ms
10,968 KB
testcase_22 AC 19 ms
10,952 KB
testcase_23 AC 13 ms
9,312 KB
testcase_24 AC 13 ms
9,324 KB
testcase_25 AC 6 ms
5,888 KB
testcase_26 AC 10 ms
7,784 KB
testcase_27 AC 23 ms
12,212 KB
testcase_28 AC 14 ms
9,308 KB
testcase_29 AC 13 ms
9,436 KB
testcase_30 AC 972 ms
198,872 KB
testcase_31 AC 980 ms
198,932 KB
testcase_32 AC 976 ms
198,860 KB
testcase_33 AC 983 ms
198,916 KB
testcase_34 AC 1,015 ms
198,088 KB
testcase_35 AC 1,026 ms
199,040 KB
testcase_36 AC 987 ms
193,852 KB
testcase_37 AC 970 ms
193,856 KB
testcase_38 AC 1,000 ms
198,336 KB
testcase_39 AC 1,010 ms
198,676 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 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 760 ms
198,912 KB
testcase_47 AC 762 ms
198,924 KB
testcase_48 AC 759 ms
198,924 KB
testcase_49 AC 679 ms
183,552 KB
testcase_50 AC 748 ms
197,776 KB
testcase_51 AC 758 ms
198,932 KB
testcase_52 AC 1,010 ms
198,872 KB
testcase_53 AC 989 ms
195,556 KB
testcase_54 AC 1,005 ms
198,936 KB
testcase_55 AC 1,012 ms
198,924 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 sum=0;
            int j;
            for(j=i;j<n;j++){
                sum+=v[j];
                if(sum>x) break;
            }
            t_l[i]=j-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