結果

問題 No.973 余興
ユーザー fumofumofunifumofumofuni
提出日時 2022-08-19 18:05:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,787 ms / 4,000 ms
コード長 2,950 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 207,476 KB
実行使用メモリ 102,008 KB
最終ジャッジ日時 2024-04-16 21:42:35
合計ジャッジ時間 111,860 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,399 ms
101,880 KB
testcase_01 AC 3,416 ms
101,880 KB
testcase_02 AC 3,570 ms
101,880 KB
testcase_03 AC 3,758 ms
101,748 KB
testcase_04 AC 3,411 ms
101,880 KB
testcase_05 AC 3,415 ms
101,756 KB
testcase_06 AC 3,556 ms
101,880 KB
testcase_07 AC 3,527 ms
101,848 KB
testcase_08 AC 3,481 ms
101,624 KB
testcase_09 AC 3,787 ms
101,756 KB
testcase_10 AC 3,312 ms
97,784 KB
testcase_11 AC 924 ms
38,912 KB
testcase_12 AC 916 ms
38,912 KB
testcase_13 AC 916 ms
38,656 KB
testcase_14 AC 903 ms
38,784 KB
testcase_15 AC 74 ms
7,808 KB
testcase_16 AC 76 ms
7,808 KB
testcase_17 AC 46 ms
6,272 KB
testcase_18 AC 60 ms
6,912 KB
testcase_19 AC 60 ms
6,784 KB
testcase_20 AC 45 ms
6,272 KB
testcase_21 AC 74 ms
7,680 KB
testcase_22 AC 74 ms
7,552 KB
testcase_23 AC 58 ms
6,940 KB
testcase_24 AC 58 ms
6,944 KB
testcase_25 AC 27 ms
5,376 KB
testcase_26 AC 45 ms
6,016 KB
testcase_27 AC 90 ms
8,320 KB
testcase_28 AC 58 ms
7,040 KB
testcase_29 AC 59 ms
6,784 KB
testcase_30 AC 3,121 ms
101,752 KB
testcase_31 AC 3,239 ms
101,876 KB
testcase_32 AC 3,103 ms
101,748 KB
testcase_33 AC 3,128 ms
101,884 KB
testcase_34 AC 3,134 ms
101,500 KB
testcase_35 AC 3,176 ms
101,872 KB
testcase_36 AC 2,955 ms
99,316 KB
testcase_37 AC 2,977 ms
99,188 KB
testcase_38 AC 3,115 ms
101,496 KB
testcase_39 AC 3,055 ms
101,624 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 3,034 ms
101,884 KB
testcase_47 AC 3,009 ms
101,884 KB
testcase_48 AC 3,008 ms
102,008 KB
testcase_49 AC 2,788 ms
94,076 KB
testcase_50 AC 2,987 ms
101,116 KB
testcase_51 AC 3,062 ms
101,752 KB
testcase_52 AC 3,036 ms
101,752 KB
testcase_53 AC 3,066 ms
99,956 KB
testcase_54 AC 3,058 ms
101,876 KB
testcase_55 AC 3,043 ms
101,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,0,-1,1,1,-1,-1,0};
const ll dx[9]={1,0,-1,0,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
struct BIT{
  int n;
  T def;
  vector<T> data;
  function<T(T,T)> fx;
  BIT(int _n,T _def,function<T(T,T)> _fx){
    n=_n;def=_def;fx=_fx;
    data.resize(n,def);
  }
  void update(int a,T val){
    for(int x=a;x<n;x|=x+1){
      data[x]=fx(data[x],val);
    }
  }
  T fold(int a){
    T ret=def;
    for(int x=a-1;x>=0;x=(x&(x+1))-1){
      ret=fx(ret,data[x]);
    }
    return ret;
  }
};

int main(){
    ll n,x;cin >> n >> x;
    vl a(n);rep(i,n)cin >> a[i];
    vl cum(n+1);rep(i,n)cum[i+1]=cum[i]+a[i];
    vector<BIT<int16_t>> stl,str;
    BIT<int16_t> tmp(n,0,[](int16_t a,int16_t b){return a+b;});
    rep(i,n){
        stl.emplace_back(tmp);
        str.emplace_back(tmp);
    }
    rep(i,n)stl[i].update(i,1);
    rep(i,n)str[i].update(i,1);
    for(ll len=2;len<=n;len++){
        for(ll l=0;l<n-len+1;l++){
            ll r=l+len;
            ll nl,nr;
            {
                ll ok=l,ng=r+1;
                while(ng-ok>1){
                    ll mid=(ok+ng)>>1;
                    if(cum[mid]-cum[l]<=x)ok=mid;
                    else ng=mid;
                }
                nl=ok;
            }
            {
                ll ok=r,ng=l-1;
                while(ok-ng>1){
                    ll mid=(ok+ng)>>1;
                    if(cum[r]-cum[mid]<=x)ok=mid;
                    else ng=mid;
                }
                nr=ok;
            }
            //cout << l <<" " << r <<" " << nl <<" " << nr << endl;
            auto f=stl[l].fold(r)-stl[l].fold(nr-1)+str[r-1].fold(nl+1)-str[r-1].fold(l);
            //auto f=stl[l].query(nr-1,r)+str[r-1].query(l,nl+1);
            if(!f)stl[l].update(r-1,1);
            if(!f)str[r-1].update(l,1);
        }
    }
    /*rep(i,n){
        rep(j,n)cout << stl[i][j] <<" ";cout << endl;
    }*/
    if(stl[0].fold(n)-stl[0].fold(n-1)==1)cout << "B" << endl;
    else cout << "A" << endl;
}
0