結果
| 問題 |
No.973 余興
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2024-11-24 19:01:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 702 ms / 4,000 ms |
| コード長 | 4,170 bytes |
| コンパイル時間 | 2,327 ms |
| コンパイル使用メモリ | 206,412 KB |
| 最終ジャッジ日時 | 2025-02-25 06:08:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 54 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
//fastset
// https://www.dropbox.com/s/1zxohqaxrb87uft/Gifted_Infants_The_University_of_Tokyo___erated_files-job_14.pdf?dl=0
using uint = unsigned int ; using ll = long long ; using ull = unsigned long long ; template < class T > using V = vector <T>; template < class T > using VV = V <V<T>>;
int popcnt ( uint x ) { return __builtin_popcount(x); } int popcnt ( ull x ) { return __builtin_popcountll(x); } int bsr ( uint x ) { return 31 - __builtin_clz(x); } int bsr ( ull x ) { return 63 - __builtin_clzll(x); } int bsf ( uint x ) { return __builtin_ctz(x); } int bsf ( ull x ) { return __builtin_ctzll(x); }
struct FastSet {
static constexpr uint B = 64 ;
int n, lg;
VV<ull> seg;
FastSet( int _n) : n(_n) {
do {
seg.push_back(V<ull>((_n + B - 1 ) / B));
_n = (_n + B - 1 ) / B;
}while (_n > 1 );
lg = seg.size();
}
bool operator []( int i) const {
return (seg[ 0 ][i / B] >> (i % B) & 1 ) != 0 ;
}
void set ( int i) {
for ( int h = 0 ; h < lg; h++) {
seg[h][i / B] |= 1ULL << (i % B); i /= B;
}
}
void reset ( int i) {
for ( int h = 0 ; h < lg; h++) {
seg[h][i / B] &= ~( 1ULL << (i % B));
if (seg[h][i / B]) break ;
i /= B;
}
}
int next ( int i) {
if (i < 0) i = 0;
if (i > n) i = n;
for ( int h = 0 ; h < lg; h++) {
if (i / B == seg[h].size()) break ;
ull d = seg[h][i / B] >> (i % B);
if (!d) {
i = i / B + 1 ;
continue ;
}
i += bsf(d);
for ( int g = h - 1 ; g >= 0 ; g--) {
i *= B; i += bsf(seg[g][i / B]);
}
return i;
}
return n;
}
// i以上
int prev ( int i) {
if (i < 0) i = 0;
if (i > n) i = n;
i--;
for ( int h = 0 ; h < lg; h++) {
if (i == -1 ) break ;
ull d = seg[h][i / B] << ( 63 - i % 64 );
if (!d) {
i = i / B - 1 ;
continue ;
}
i += bsr(d) - (B - 1 );
for ( int g = h - 1 ; g >= 0 ; g--) {
i *= B;
i += bsr(seg[g][i / B]);
}
return i;
}
return -1 ;
}
// i未満
};
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
ll N;cin>>N;
ll X;cin>>X;
vl S(N+1);
for(int i=0;i<N;i++){
ll x;cin>>x;
S[i+1]=S[i]+x;
}
vector<FastSet> L(N+1,FastSet(N+1)),R(N+1,FastSet(N+1));
for(int i=0;i<N;i++){
L[i].set(i+1);
R[i+1].set(i);
}
for(int len=2;len<=N;len++){
for(int l=0;l+len<=N;l++){
int r=l+len;
bool ok=false;
{
int x=L[l].prev(r);
if(x>=l&&S[r]-S[x]<=X) ok=true;
}
{
int x=R[r].next(l);
if(x<=r&&S[x]-S[l]<=X) ok=true;
}
if(!ok){
L[l].set(r);
R[r].set(l);
}
}
}
if(L[0][N]) cout<<"B\n";
else cout<<"A\n";
}
Rubikun