結果

問題 No.973 余興
ユーザー beetbeet
提出日時 2020-01-17 21:56:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,808 ms / 4,000 ms
コード長 2,167 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 203,628 KB
実行使用メモリ 266,204 KB
最終ジャッジ日時 2023-09-08 02:44:37
合計ジャッジ時間 52,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,761 ms
265,988 KB
testcase_01 AC 1,737 ms
266,204 KB
testcase_02 AC 1,763 ms
265,780 KB
testcase_03 AC 1,753 ms
265,888 KB
testcase_04 AC 1,762 ms
266,080 KB
testcase_05 AC 1,745 ms
266,148 KB
testcase_06 AC 1,685 ms
265,920 KB
testcase_07 AC 1,740 ms
265,780 KB
testcase_08 AC 1,808 ms
265,016 KB
testcase_09 AC 1,803 ms
266,144 KB
testcase_10 AC 1,656 ms
256,448 KB
testcase_11 AC 385 ms
103,284 KB
testcase_12 AC 389 ms
103,304 KB
testcase_13 AC 388 ms
102,468 KB
testcase_14 AC 375 ms
102,492 KB
testcase_15 AC 45 ms
17,208 KB
testcase_16 AC 45 ms
17,552 KB
testcase_17 AC 26 ms
12,668 KB
testcase_18 AC 36 ms
14,944 KB
testcase_19 AC 36 ms
14,984 KB
testcase_20 AC 26 ms
12,520 KB
testcase_21 AC 46 ms
17,328 KB
testcase_22 AC 45 ms
17,260 KB
testcase_23 AC 35 ms
14,944 KB
testcase_24 AC 35 ms
15,024 KB
testcase_25 AC 15 ms
9,568 KB
testcase_26 AC 26 ms
12,460 KB
testcase_27 AC 57 ms
18,924 KB
testcase_28 AC 36 ms
15,032 KB
testcase_29 AC 36 ms
14,680 KB
testcase_30 AC 1,210 ms
266,080 KB
testcase_31 AC 1,216 ms
266,028 KB
testcase_32 AC 1,219 ms
265,988 KB
testcase_33 AC 1,231 ms
265,948 KB
testcase_34 AC 1,230 ms
264,944 KB
testcase_35 AC 1,216 ms
266,028 KB
testcase_36 AC 1,208 ms
259,504 KB
testcase_37 AC 1,203 ms
259,624 KB
testcase_38 AC 1,265 ms
265,404 KB
testcase_39 AC 1,227 ms
265,860 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1,203 ms
266,068 KB
testcase_47 AC 1,227 ms
266,116 KB
testcase_48 AC 1,221 ms
265,988 KB
testcase_49 AC 1,152 ms
246,596 KB
testcase_50 AC 1,229 ms
264,052 KB
testcase_51 AC 1,282 ms
266,032 KB
testcase_52 AC 1,286 ms
266,076 KB
testcase_53 AC 1,238 ms
261,972 KB
testcase_54 AC 1,215 ms
266,200 KB
testcase_55 AC 1,237 ms
265,888 KB
権限があれば一括ダウンロードができます

ソースコード

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+1,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;
      long long sm=0;
      while(j>=0&&sm+as[j]<=x){
        sm+=as[j];
        j--;
      }
      ls[i]=j+1;
    }
    {
      int j=i+1;
      long long sm=0;
      while(j<n&&sm+as[j]<=x){
        sm+=as[j];
        j++;
      }
      rs[i]=j-1;
    }
    // cout<<i<<":"<<ls[i]<<" "<<rs[i]<<endl;
  }

  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;

      // cout<<l<<" "<<r<<endl;
      if(r+1<n){
        // [r+1, rs[r]]
        bl[l].add0(r+1,1);
        bl[l].add0(rs[r]+1,-1);
      }
      // cout<<l<<" "<<r<<endl;
      if(l>0){
        // [ls[l], l-1]
        br[r].add0(ls[l],1);
        br[r].add0(l,-1);
      }
    }
  }

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