結果

問題 No.973 余興
ユーザー utouto97utouto97
提出日時 2020-01-20 20:54:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,258 ms / 4,000 ms
コード長 2,327 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 150,556 KB
実行使用メモリ 394,632 KB
最終ジャッジ日時 2023-09-15 21:52:13
合計ジャッジ時間 72,244 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,008 ms
394,584 KB
testcase_01 AC 1,967 ms
394,500 KB
testcase_02 AC 1,949 ms
394,280 KB
testcase_03 AC 1,974 ms
394,296 KB
testcase_04 AC 1,952 ms
394,476 KB
testcase_05 AC 1,979 ms
394,532 KB
testcase_06 AC 1,999 ms
394,376 KB
testcase_07 AC 2,003 ms
394,220 KB
testcase_08 AC 2,002 ms
393,192 KB
testcase_09 AC 1,954 ms
394,568 KB
testcase_10 AC 1,907 ms
378,972 KB
testcase_11 AC 678 ms
143,964 KB
testcase_12 AC 667 ms
144,228 KB
testcase_13 AC 655 ms
142,852 KB
testcase_14 AC 640 ms
142,908 KB
testcase_15 AC 48 ms
19,088 KB
testcase_16 AC 50 ms
19,424 KB
testcase_17 AC 28 ms
12,704 KB
testcase_18 AC 38 ms
15,792 KB
testcase_19 AC 38 ms
16,188 KB
testcase_20 AC 27 ms
12,436 KB
testcase_21 AC 49 ms
18,884 KB
testcase_22 AC 48 ms
18,848 KB
testcase_23 AC 38 ms
16,052 KB
testcase_24 AC 39 ms
15,728 KB
testcase_25 AC 16 ms
8,792 KB
testcase_26 AC 27 ms
12,628 KB
testcase_27 AC 60 ms
21,600 KB
testcase_28 AC 38 ms
16,040 KB
testcase_29 AC 37 ms
15,708 KB
testcase_30 AC 2,175 ms
394,440 KB
testcase_31 AC 2,120 ms
394,628 KB
testcase_32 AC 2,154 ms
394,440 KB
testcase_33 AC 2,134 ms
394,284 KB
testcase_34 AC 2,258 ms
392,652 KB
testcase_35 AC 2,134 ms
394,496 KB
testcase_36 AC 2,051 ms
384,072 KB
testcase_37 AC 2,088 ms
383,884 KB
testcase_38 AC 2,165 ms
393,312 KB
testcase_39 AC 2,111 ms
393,700 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2,086 ms
394,632 KB
testcase_47 AC 2,100 ms
394,320 KB
testcase_48 AC 2,075 ms
394,552 KB
testcase_49 AC 1,944 ms
363,876 KB
testcase_50 AC 2,109 ms
391,404 KB
testcase_51 AC 2,068 ms
394,488 KB
testcase_52 AC 2,148 ms
394,560 KB
testcase_53 AC 2,080 ms
387,684 KB
testcase_54 AC 2,028 ms
394,492 KB
testcase_55 AC 2,120 ms
394,292 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+1) cout << lr[i] << " ";
//  cout << endl;
//  rep(i, 0, n+1) 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(len, 1, n+1){
    rep(left, 0, n-len+1){
      int right = left+len;
      bool lose = true;

      int s = max(left, rl[right]);
      if(bitl[left].query0(s, right)) lose = false;
      int t = min(right, lr[left]+1);
      if(bitr[right].query0(left, t)) lose = false;

      if(lose){
        bitl[left].add0(right, 1);
        bitr[right].add0(left, 1);
      }
    }
  }

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

//  rep(i, 0, n){
//    rep(j, 1, n+1) {
//      cout << bitl[i].query0(j, j+1) << " ";
//    }
//    cout << endl;
//  }
//  rep(i, 0, n){
//    rep(j, 1, n+1) {
//      cout << bitr[i].query0(j, j+1) << " ";
//    }
//    cout << endl;
//  }

  return 0;
}

0