結果
| 問題 |
No.973 余興
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-19 18:09:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,982 bytes |
| コンパイル時間 | 3,396 ms |
| コンパイル使用メモリ | 210,076 KB |
| 最終ジャッジ日時 | 2025-01-31 00:29:24 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 TLE * 31 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#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;
}