結果

問題 No.973 余興
ユーザー mugen_1337mugen_1337
提出日時 2021-04-13 16:10:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,142 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 211,316 KB
実行使用メモリ 202,428 KB
最終ジャッジ日時 2023-09-12 08:30:07
合計ジャッジ時間 66,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,834 ms
202,108 KB
testcase_01 WA -
testcase_02 AC 1,826 ms
202,080 KB
testcase_03 WA -
testcase_04 AC 1,835 ms
202,208 KB
testcase_05 AC 1,831 ms
202,116 KB
testcase_06 AC 1,830 ms
202,336 KB
testcase_07 AC 1,826 ms
202,080 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1,766 ms
202,172 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 208 ms
201,772 KB
testcase_16 AC 209 ms
202,032 KB
testcase_17 WA -
testcase_18 AC 195 ms
201,892 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 196 ms
201,672 KB
testcase_24 AC 197 ms
201,600 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 217 ms
201,624 KB
testcase_28 AC 196 ms
201,908 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,737 ms
202,200 KB
testcase_32 WA -
testcase_33 AC 1,748 ms
202,132 KB
testcase_34 WA -
testcase_35 AC 1,761 ms
202,128 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1,734 ms
202,204 KB
testcase_39 AC 1,740 ms
202,176 KB
testcase_40 WA -
testcase_41 AC 144 ms
201,672 KB
testcase_42 AC 145 ms
201,636 KB
testcase_43 WA -
testcase_44 AC 145 ms
201,776 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 1,244 ms
202,128 KB
testcase_49 WA -
testcase_50 AC 1,170 ms
202,176 KB
testcase_51 AC 1,171 ms
202,180 KB
testcase_52 AC 1,848 ms
202,080 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 1,843 ms
202,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
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;
}

vector<bitset<5001>> dp(5001);
vector<vector<int>> s_l(5001,vector<int>(5001,0)),s_r(5001,vector<int>(5001,0));

void solve(){
    int n;ll x;cin>>n>>x;
    vector<ll> v(n);
    cin>>v;

    vector<ll> s(n);
    s[0]=v[0];
    for(int i=1;i<n;i++) s[i]=s[i-1]+v[i];

    rep(i,n){
        s_l[i][i+1]=1;
        s_r[i+1][i]=1;
    }


    for(int w=2;w<=n;w++){
        for(int l=0;l+w<=n;l++){
            int r=l+w;// [l,r)
            bool win=false;
            // left
            {
                ll offset=(l==0?0:s[l-1]);
                int ri=lower_bound(begin(s),end(s),offset+x+1)-begin(s);
                // can take [l,ri)
                // int opponent_lose=rt.count(l+1,ri+1,r,r+1);
                int op=s_r[r][l+1];
                if(ri+1<=5000) op-=s_r[r][ri+1];
                if(op>0) win=true;
            }
            // right
            {
                int li=lower_bound(begin(s),end(s),s[r-1]-x+1)-begin(s);
                // can take [li,r)
                // int opponent_lose=rt.count(l,l+1,li,r-1);
                int op=s_l[l][r-1];
                if(li) op-=s_l[l][li-1];
                if(op>0) win=true;
            }
            dp[l][r]=win;
            if(!win){
                s_l[l][r]=s_l[l][r-1]+1;
                s_r[r][l]=s_r[r][l+1]+1;
            }
        }
    }
    cout<<(dp[0][n]?"A":"B")<<endl;
}

void naive(){
    int n;ll x;cin>>n>>x;
    vector<ll> v(n);
    cin>>v;



    for(int w=2;w<=n;w++){
        for(int l=0;l+w<=n;l++){
            int r=l+w;// [l,r)
            bool win=false;
            // left
            {
                ll s=v[l];
                for(int i=l+1;i<r and s<=x;i++){
                    if(!dp[i][r]) win=true;
                    s+=v[i];
                }
            }
            // right
            {
                ll s=v[r-1];
                for(int i=r-1;i>l and s<=x;i--){
                    if(!dp[l][i]) win=true;
                    s+=v[i-1];
                }
            }
            dp[l][r]=win;
        }
    }
    cout<<(dp[0][n]?"A":"B")<<endl;
}

signed main(){
    // naive();
    solve();
    return 0;
}
0