結果

問題 No.973 余興
ユーザー utouto97utouto97
提出日時 2020-01-20 19:22:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,089 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 151,000 KB
実行使用メモリ 394,832 KB
最終ジャッジ日時 2023-09-15 21:38:49
合計ジャッジ時間 66,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,880 ms
394,620 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1,928 ms
394,524 KB
testcase_05 WA -
testcase_06 AC 1,863 ms
394,216 KB
testcase_07 WA -
testcase_08 AC 1,899 ms
393,208 KB
testcase_09 AC 1,864 ms
394,620 KB
testcase_10 WA -
testcase_11 AC 607 ms
144,020 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 607 ms
142,972 KB
testcase_15 AC 43 ms
18,804 KB
testcase_16 AC 43 ms
19,076 KB
testcase_17 WA -
testcase_18 AC 34 ms
15,644 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 42 ms
18,908 KB
testcase_22 AC 42 ms
18,856 KB
testcase_23 AC 34 ms
15,640 KB
testcase_24 AC 35 ms
15,716 KB
testcase_25 AC 15 ms
8,852 KB
testcase_26 AC 25 ms
12,612 KB
testcase_27 WA -
testcase_28 AC 34 ms
15,632 KB
testcase_29 AC 32 ms
15,688 KB
testcase_30 AC 1,864 ms
394,640 KB
testcase_31 AC 1,891 ms
394,560 KB
testcase_32 AC 1,877 ms
394,556 KB
testcase_33 AC 1,872 ms
394,268 KB
testcase_34 WA -
testcase_35 AC 1,891 ms
394,532 KB
testcase_36 AC 1,819 ms
383,972 KB
testcase_37 AC 1,824 ms
383,964 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 WA -
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1,887 ms
394,520 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 1,725 ms
363,932 KB
testcase_50 AC 1,950 ms
391,320 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 1,858 ms
394,524 KB
testcase_55 AC 1,888 ms
394,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

template<class T>
class BinaryIndexedTree
{
public:
  int n;
  vector<T> bit;

  BinaryIndexedTree():n(-1){}

  BinaryIndexedTree(int n_, T d):n(n_),bit(n_+1,d){}

  T sum(int i)
  {
    T s = 0;
    while(i > 0){
      s += bit[i];
      i -= i&-i;
    }
    return s;
  }

  void add(int i, T x)
  {
    if(i == 0) return;
    while(i <= n){
      bit[i] += x;
      i += i&-i;
    }
  }

  T sum0(int i)
  {
    return sum(i+1);
  }

  void add0(int i, T x)
  {
    add(i+1, x);
  }

  T query(int l, int r)
  {
    return sum(r-1)-sum(l-1);
  }

  T query0(int l, int r)
  {
    return sum(r)-sum(l);
  }
};

signed main() {
  int n, x;
  cin >> n >> x;
  
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  vi lr(n+1), rl(n+1);
  int r = 0, sum = 0;
  rep(l, 0, n){
    while(r < n and sum + a[r] <= x){
      sum += a[r];
      r++;
      rl[r] = l;
    }

    lr[l] = r;

    if(l == r) r++;
    else sum -= a[l];
  }

//  rep(i, 0, n) cout << lr[i] << " ";
//  cout << endl;
//  rep(i, 0, n) cout << rl[i] << " ";
//  cout << endl;

  vector<BinaryIndexedTree<int>> bitl(n+1, BinaryIndexedTree<int>(n+1, 0));
  vector<BinaryIndexedTree<int>> bitr(n+1, BinaryIndexedTree<int>(n+1, 0));
  rep(i, 0, n+1){ bitl[i].add0(i, 1); bitr[i].add0(i, 1); }

  rep(len, 1, n+1){
    rep(left, 0, n-len+1){
      int right = left+len;

      int s = min(lr[left], right);
      int t = max(left, rl[right]);

      if(((s-left) - bitr[r].query0(left+1, s+1)) or ((right-t) - bitl[left].query0(t, right))){
        bitl[left].add0(right, 1);
        bitr[right].add0(left, 1);
      }
    }
  }

  if(bitl[0].query0(n, n+1)) cout << "A" << endl;
  else cout << "B" << endl;

  return 0;
}

0