結果

問題 No.973 余興
ユーザー beetbeet
提出日時 2020-01-17 21:46:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,945 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 205,056 KB
実行使用メモリ 266,068 KB
最終ジャッジ日時 2023-09-08 02:19:42
合計ジャッジ時間 73,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 1,795 ms
265,904 KB
testcase_03 AC 1,832 ms
265,820 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 1,789 ms
265,808 KB
testcase_07 WA -
testcase_08 AC 1,830 ms
264,960 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 39 ms
14,868 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 48 ms
17,220 KB
testcase_22 AC 48 ms
17,296 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 1,312 ms
265,832 KB
testcase_34 AC 1,493 ms
264,796 KB
testcase_35 RE -
testcase_36 AC 1,295 ms
259,432 KB
testcase_37 AC 1,288 ms
259,444 KB
testcase_38 RE -
testcase_39 WA -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 RE -
testcase_46 RE -
testcase_47 WA -
testcase_48 RE -
testcase_49 RE -
testcase_50 WA -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT(int n_):n(n_+1),bit(n,0){}

  T sum(int i){
    T s(0);
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }

  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }

  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }

  // [l, r)
  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }

  T sum0(int i){
    return sum(i+1);
  }

  void add0(int i,T a){
    add(i+1,a);
  }

  T query0(int l,int r){
    return sum(r)-sum(l);
  }
};

//INSERT ABOVE HERE
const int MAX = 5050;
int dp[MAX][MAX]={};

signed main(){
  int n,x;
  cin>>n>>x;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  //vector<int> sm(n+1,0);
  //for(int i=0;i<n;i++) sm[i+1]=sm[i]+as[i];

  vector<int> ls(n),rs(n);
  for(int i=0;i<n;i++){
    {
      int j=i-1,sm=0;
      while(j>=0&&sm+as[j]<=x){
        sm+=as[j];
        j--;
      }
      ls[i]=j+1;
    }
    {
      int j=i+1,sm=0;
      while(j<n&&sm+as[j]<=x){
        sm+=as[j];
        j++;
      }
      rs[i]=j-1;
    }
  }

  using B = BIT<int>;
  vector<B> bl(n,B(n+1));
  vector<B> br(n,B(n+1));
  for(int w=1;w<=n;w++){
    for(int l=0;l+w<=n;l++){
      // [l, r]
      int r=l+w-1;
      dp[l][r]|=bl[l].sum0(r);
      dp[l][r]|=br[r].sum0(l);
      if(dp[l][r]) continue;

      bl[l].add0(r+1,1);
      bl[l].add0(rs[r]+1,-1);

      if(l){
        br[r].add0(l-1,-1);
        br[r].add0(ls[l],1);
      }
    }
  }

  cout<<(dp[0][n-1]?"A":"B")<<endl;
  return 0;
}
0