結果

問題 No.973 余興
ユーザー ChanyuhChanyuh
提出日時 2020-05-04 21:19:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,917 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 108,184 KB
実行使用メモリ 420,460 KB
最終ジャッジ日時 2023-09-07 05:31:30
合計ジャッジ時間 108,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2,604 ms
420,124 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2,599 ms
420,096 KB
testcase_05 WA -
testcase_06 AC 2,470 ms
420,240 KB
testcase_07 WA -
testcase_08 AC 2,562 ms
419,656 KB
testcase_09 AC 2,554 ms
420,276 KB
testcase_10 WA -
testcase_11 AC 1,141 ms
158,296 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,117 ms
158,028 KB
testcase_15 AC 55 ms
30,448 KB
testcase_16 AC 56 ms
30,380 KB
testcase_17 WA -
testcase_18 AC 45 ms
27,492 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 55 ms
30,344 KB
testcase_22 AC 55 ms
30,348 KB
testcase_23 AC 44 ms
27,524 KB
testcase_24 AC 43 ms
27,240 KB
testcase_25 AC 20 ms
18,764 KB
testcase_26 AC 33 ms
24,444 KB
testcase_27 WA -
testcase_28 AC 45 ms
27,500 KB
testcase_29 AC 43 ms
27,348 KB
testcase_30 AC 3,410 ms
420,096 KB
testcase_31 AC 3,545 ms
420,196 KB
testcase_32 AC 3,548 ms
420,128 KB
testcase_33 AC 3,709 ms
420,152 KB
testcase_34 WA -
testcase_35 AC 3,458 ms
420,168 KB
testcase_36 AC 3,435 ms
415,644 KB
testcase_37 AC 3,461 ms
415,708 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 WA -
testcase_45 AC 3 ms
6,092 KB
testcase_46 AC 3,402 ms
420,132 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 3,205 ms
405,032 KB
testcase_50 AC 3,262 ms
418,956 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 3,392 ms
420,368 KB
testcase_55 AC 3,317 ms
420,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;//二項演算
  T ti;//単位元
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){//sizeがn_のsegtreeを作る
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){//vによってsegtreeをbuildする
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){//k番目をxにする
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){//区間[a,b)に対しFを適応した値を返す
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){//
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }

  T &operator [] (int i) {return dat[i+n];};
};


int n;ll x;
ll a[5010];
int dp[5010][5010];
int max1[5010],max2[5010];


void solve(){
  cin >> n >> x;
  rep(i,n){
    cin >> a[i+1];
  }
  rep(i,n+2){
    rep(j,n+2){

    }
  }
  a[0]=INF;
  a[n+1]=INF;
  auto f=[](int p,int q){return p&q;};
  vector<SegmentTree<int>> seg1(n+2,SegmentTree<int>(f,1));
  //vector<SegmentTree<int>> seg2(n+2,SegmentTree<int>(f,1));
  rep(i,n+2){
    seg1[i].init(n+2);
  }
  rep(i,n+2){
    //seg2[i].init(n+2);
  }
  int j=1;ll S=a[1];
  Rep(i,1,n+1){
    while(S+a[j+1]<=x){
      j+=1;
      S+=a[j];
    }
    max1[i]=j;
    S-=a[i];
  }
  j=n;S=a[n];
  Per(i,1,n+1){
    while(S+a[j-1]<=x){
      j-=1;
      S+=a[j];
    }
    max2[i]=j;
    S-=a[i];
  }
  // rep(i,n){
  //   cout << max1[i+1] << " "; 
  // }
  // cout << "" << endl;
  // rep(i,n){
  //   cout << max2[i+1] << " "; 
  // }
  // cout << "" << endl;
  Rep(d,1,n+2){
    rep(i,n+2-d){
      int j=i+d;
      if(d==1){
        dp[i][j]=1;
      }
      else{
        int s=1;
        s&=seg1[j].query(i+1,min(max1[i+1]+1,j));
        //s&=seg2[i].query(max(i+1,max2[j-1]),j);
        dp[i][j]=s^1;
      }
      //cout << i << " " << j << " " << dp[i][j] << endl;
      seg1[j].set_val(i,dp[i][j]);
      //seg2[i].set_val(j,dp[i][j]);
    }
  }
  if(dp[0][n+1]) cout << "A" << endl;
  else cout << "B" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0