#include 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<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } vector> dp(5001); #include #include using namespace __gnu_pbds; // x軸だけ先に読めれば, オンラインにできる. 僕にはこれが限界 template struct RangeTree{ // pair value, id using set_pbds=tree,null_type,less>,rb_tree_tag,tree_order_statistics_node_update>; map cnt; vector seg; vector xs; int sz; RangeTree(vector x_):xs(x_){ sort(begin(xs),end(xs)); xs.erase(unique(begin(xs),end(xs)),end(xs)); sz=1; while(sz<(int)xs.size()) sz<<=1; while((int)xs.size()::max()); seg.resize(2*sz); } void add(Tx x,Ty y){ int k=lower_bound(begin(xs),end(xs),x)-begin(xs); assert(xs[k]==x); k+=sz; int id=cnt[y]++; for(;k;k>>=1) seg[k].insert({y,id}); } void erase(Tx x,Ty y){ int k=lower_bound(begin(xs),end(xs))-begin(xs); k+=sz; int id=--cnt[y]; for(;k;k>>=1) seg[k].erase({y,id}); } // [xleft, xright), [ylow, yhigh) int count(Tx xl,Tx xr,Ty yl,Ty yh){ int l=lower_bound(begin(xs),end(xs),xl)-begin(xs); int r=lower_bound(begin(xs),end(xs),xr)-begin(xs); l+=sz,r+=sz; int ret=0; for(;l>=1,r>>=1){ if(l&1){ ret+=seg[l].order_of_key({yh,-1})-seg[l].order_of_key({yl,-1}); l++; } if(r&1){ r--; ret+=seg[r].order_of_key({yh,-1})-seg[r].order_of_key({yl,-1}); } } return ret; } }; void solve(){ int n;ll x;cin>>n>>x; vector v(n); cin>>v; vector s(n); s[0]=v[0]; for(int i=1;i tmp(5001); iota(ALL(tmp),0); RangeTree rt(tmp); rep(i,n) rt.add(i,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); if(opponent_lose) 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); } dp[l][r]=win; if(!win){ rt.add(l,r); } } } cout<<(dp[0][n]?"A":"B")<>n>>x; vector v(n); cin>>v; assert(n<800); 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;il and s<=x;i--){ if(!dp[l][i]) win=true; s+=v[i-1]; } } dp[l][r]=win; } } cout<<(dp[0][n]?"A":"B")<