結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1,744 ms
202,172 KB
testcase_03 WA -
testcase_04 AC 1,742 ms
202,108 KB
testcase_05 AC 1,733 ms
202,104 KB
testcase_06 AC 1,730 ms
202,104 KB
testcase_07 AC 1,770 ms
202,100 KB
testcase_08 AC 1,724 ms
202,104 KB
testcase_09 AC 1,728 ms
202,172 KB
testcase_10 WA -
testcase_11 AC 698 ms
201,668 KB
testcase_12 AC 696 ms
201,976 KB
testcase_13 AC 694 ms
201,764 KB
testcase_14 AC 714 ms
201,832 KB
testcase_15 WA -
testcase_16 AC 208 ms
202,036 KB
testcase_17 AC 182 ms
201,696 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 206 ms
201,956 KB
testcase_22 AC 204 ms
201,972 KB
testcase_23 AC 194 ms
201,844 KB
testcase_24 AC 192 ms
201,584 KB
testcase_25 AC 169 ms
201,956 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 193 ms
201,760 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,785 ms
202,160 KB
testcase_32 AC 1,762 ms
202,160 KB
testcase_33 AC 1,806 ms
202,100 KB
testcase_34 AC 1,784 ms
202,236 KB
testcase_35 AC 1,786 ms
202,252 KB
testcase_36 AC 1,727 ms
202,200 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,791 ms
202,184 KB
testcase_40 WA -
testcase_41 AC 148 ms
202,008 KB
testcase_42 AC 148 ms
201,992 KB
testcase_43 WA -
testcase_44 AC 147 ms
201,664 KB
testcase_45 AC 148 ms
201,848 KB
testcase_46 WA -
testcase_47 AC 1,336 ms
202,256 KB
testcase_48 AC 1,315 ms
202,252 KB
testcase_49 AC 1,247 ms
202,092 KB
testcase_50 AC 1,324 ms
202,348 KB
testcase_51 WA -
testcase_52 AC 1,909 ms
202,108 KB
testcase_53 AC 1,860 ms
202,172 KB
testcase_54 WA -
testcase_55 AC 1,888 ms
202,104 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-2];
                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