結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,799 ms
202,136 KB
testcase_02 AC 1,777 ms
202,120 KB
testcase_03 WA -
testcase_04 AC 1,804 ms
202,288 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,780 ms
202,388 KB
testcase_09 WA -
testcase_10 AC 1,727 ms
202,252 KB
testcase_11 AC 693 ms
201,904 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 690 ms
201,968 KB
testcase_15 AC 206 ms
202,100 KB
testcase_16 AC 207 ms
201,788 KB
testcase_17 AC 181 ms
201,844 KB
testcase_18 WA -
testcase_19 AC 192 ms
202,168 KB
testcase_20 WA -
testcase_21 AC 203 ms
201,968 KB
testcase_22 AC 204 ms
201,668 KB
testcase_23 AC 194 ms
201,612 KB
testcase_24 WA -
testcase_25 AC 166 ms
201,672 KB
testcase_26 AC 180 ms
201,968 KB
testcase_27 AC 216 ms
201,852 KB
testcase_28 WA -
testcase_29 AC 192 ms
201,776 KB
testcase_30 AC 1,758 ms
202,116 KB
testcase_31 AC 1,852 ms
202,112 KB
testcase_32 AC 1,849 ms
202,224 KB
testcase_33 AC 1,763 ms
202,192 KB
testcase_34 WA -
testcase_35 AC 1,721 ms
202,120 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1,738 ms
202,116 KB
testcase_39 AC 1,751 ms
202,440 KB
testcase_40 AC 145 ms
201,732 KB
testcase_41 AC 147 ms
201,768 KB
testcase_42 AC 145 ms
201,900 KB
testcase_43 AC 143 ms
202,048 KB
testcase_44 AC 145 ms
202,040 KB
testcase_45 WA -
testcase_46 AC 1,218 ms
202,244 KB
testcase_47 WA -
testcase_48 AC 1,249 ms
202,136 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1,800 ms
202,128 KB
testcase_54 WA -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

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,r)
                // int opponent_lose=rt.count(l+1,ri+1,r,r+1);
                int op=s_r[r][l+1];
                if(ri+2<=5000) op-=s_r[r][ri+2];
                if(op) 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) 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