結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,797 ms
202,188 KB
testcase_02 AC 1,817 ms
202,208 KB
testcase_03 WA -
testcase_04 AC 1,769 ms
202,056 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,775 ms
202,208 KB
testcase_09 WA -
testcase_10 AC 1,701 ms
202,204 KB
testcase_11 AC 683 ms
202,068 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 674 ms
201,784 KB
testcase_15 AC 202 ms
201,612 KB
testcase_16 AC 207 ms
201,776 KB
testcase_17 AC 179 ms
201,800 KB
testcase_18 WA -
testcase_19 AC 192 ms
202,120 KB
testcase_20 WA -
testcase_21 AC 204 ms
201,784 KB
testcase_22 AC 204 ms
201,624 KB
testcase_23 AC 193 ms
201,616 KB
testcase_24 WA -
testcase_25 AC 165 ms
201,872 KB
testcase_26 AC 178 ms
201,780 KB
testcase_27 AC 212 ms
201,856 KB
testcase_28 WA -
testcase_29 AC 190 ms
202,044 KB
testcase_30 AC 1,735 ms
202,108 KB
testcase_31 AC 1,718 ms
202,160 KB
testcase_32 AC 1,728 ms
202,060 KB
testcase_33 AC 1,709 ms
202,128 KB
testcase_34 WA -
testcase_35 AC 1,742 ms
202,064 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1,700 ms
202,168 KB
testcase_39 AC 1,729 ms
202,208 KB
testcase_40 AC 145 ms
202,040 KB
testcase_41 AC 144 ms
201,752 KB
testcase_42 AC 146 ms
201,964 KB
testcase_43 AC 144 ms
201,544 KB
testcase_44 AC 144 ms
201,664 KB
testcase_45 WA -
testcase_46 AC 1,232 ms
202,092 KB
testcase_47 WA -
testcase_48 AC 1,202 ms
202,060 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1,788 ms
202,308 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,ri)
                // 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!=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