結果

問題 No.973 余興
ユーザー ChanyuhChanyuh
提出日時 2020-05-04 22:11:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,296 ms / 4,000 ms
コード長 4,041 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 100,268 KB
実行使用メモリ 161,696 KB
最終ジャッジ日時 2023-09-07 06:45:08
合計ジャッジ時間 39,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 847 ms
161,300 KB
testcase_01 AC 865 ms
161,584 KB
testcase_02 AC 787 ms
161,496 KB
testcase_03 AC 793 ms
161,516 KB
testcase_04 AC 794 ms
161,504 KB
testcase_05 AC 801 ms
161,564 KB
testcase_06 AC 803 ms
161,516 KB
testcase_07 AC 787 ms
161,452 KB
testcase_08 AC 792 ms
161,392 KB
testcase_09 AC 791 ms
161,508 KB
testcase_10 AC 771 ms
158,600 KB
testcase_11 AC 408 ms
78,952 KB
testcase_12 AC 408 ms
78,988 KB
testcase_13 AC 403 ms
78,888 KB
testcase_14 AC 406 ms
78,612 KB
testcase_15 AC 32 ms
23,496 KB
testcase_16 AC 33 ms
23,768 KB
testcase_17 AC 22 ms
18,340 KB
testcase_18 AC 27 ms
20,024 KB
testcase_19 AC 27 ms
19,924 KB
testcase_20 AC 21 ms
18,244 KB
testcase_21 AC 32 ms
23,520 KB
testcase_22 AC 32 ms
23,524 KB
testcase_23 AC 27 ms
19,920 KB
testcase_24 AC 27 ms
19,948 KB
testcase_25 AC 14 ms
16,020 KB
testcase_26 AC 21 ms
18,328 KB
testcase_27 AC 37 ms
25,020 KB
testcase_28 AC 27 ms
19,892 KB
testcase_29 AC 26 ms
19,756 KB
testcase_30 AC 1,240 ms
161,560 KB
testcase_31 AC 1,224 ms
161,696 KB
testcase_32 AC 1,241 ms
161,620 KB
testcase_33 AC 1,204 ms
161,652 KB
testcase_34 AC 1,233 ms
161,384 KB
testcase_35 AC 1,218 ms
161,516 KB
testcase_36 AC 1,197 ms
159,924 KB
testcase_37 AC 1,210 ms
159,964 KB
testcase_38 AC 1,232 ms
161,512 KB
testcase_39 AC 1,239 ms
161,412 KB
testcase_40 AC 2 ms
5,468 KB
testcase_41 AC 3 ms
5,644 KB
testcase_42 AC 2 ms
5,432 KB
testcase_43 AC 2 ms
5,540 KB
testcase_44 AC 2 ms
5,484 KB
testcase_45 AC 4 ms
8,380 KB
testcase_46 AC 1,230 ms
161,568 KB
testcase_47 AC 1,209 ms
161,572 KB
testcase_48 AC 1,226 ms
161,636 KB
testcase_49 AC 1,138 ms
154,332 KB
testcase_50 AC 1,296 ms
161,044 KB
testcase_51 AC 1,194 ms
161,572 KB
testcase_52 AC 1,200 ms
161,524 KB
testcase_53 AC 1,174 ms
160,460 KB
testcase_54 AC 1,197 ms
161,640 KB
testcase_55 AC 1,198 ms
161,504 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];
bool dp[5010][5010];
int S1[5010][5010],S2[5010][5010];
int max1[5010],max2[5010];


void solve(){
  cin >> n >> x;
  rep(i,n){
    cin >> a[i+1];
  }
  
  a[0]=INF;
  a[n+1]=INF;
  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;
  bool ans;
  Rep(d,1,n+2){
    rep(i,n+2-d){
      int j=i+d;
      dp[i][j]=1;
      if(d==1){
        dp[i][j]=1;
      }
      else{
        //cout << seg1[j].query(i+1,min(max1[i+1]+1,j)) << endl;
        //cout << seg2[i].query(max(i+1,max2[j-1]),j) << endl;
        dp[i][j]&=(S1[j][i+1]-S1[j][min(max1[i+1]+1,j)]==min(max1[i+1]+1,j)-i-1);
        dp[i][j]&=(S2[i][j-1]-S2[i][max(i,max2[j-1]-1)]==j-1-max(i,max2[j-1]-1));
        dp[i][j]^=1;
        //cout << s << endl;
      }
      
      //cout << i << " " << j << " " << dp[i][j] << endl;
      //cout << S1[j][i+1]-S1[j][min(max1[i+1]+1,j)] << endl;
      //cout << S2[i][j-1]-S2[i][max(i,max2[j-1]-1)] << endl;
      S1[j][i]=S1[j][i+1]+dp[i][j];
      S2[i][j]=S2[i][j-1]+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