結果

問題 No.973 余興
ユーザー 👑 emthrmemthrm
提出日時 2020-01-18 06:40:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 883 ms / 4,000 ms
コード長 2,301 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 203,308 KB
実行使用メモリ 199,000 KB
最終ジャッジ日時 2023-09-09 03:39:30
合計ジャッジ時間 31,990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 757 ms
198,872 KB
testcase_01 AC 754 ms
198,884 KB
testcase_02 AC 747 ms
198,988 KB
testcase_03 AC 750 ms
198,672 KB
testcase_04 AC 759 ms
198,824 KB
testcase_05 AC 757 ms
198,876 KB
testcase_06 AC 749 ms
198,612 KB
testcase_07 AC 758 ms
198,668 KB
testcase_08 AC 750 ms
197,928 KB
testcase_09 AC 756 ms
198,936 KB
testcase_10 AC 719 ms
191,020 KB
testcase_11 AC 224 ms
73,424 KB
testcase_12 AC 225 ms
73,688 KB
testcase_13 AC 226 ms
72,944 KB
testcase_14 AC 221 ms
73,020 KB
testcase_15 AC 18 ms
10,848 KB
testcase_16 AC 19 ms
11,172 KB
testcase_17 AC 11 ms
8,000 KB
testcase_18 AC 13 ms
9,268 KB
testcase_19 AC 13 ms
9,324 KB
testcase_20 AC 10 ms
7,732 KB
testcase_21 AC 18 ms
11,012 KB
testcase_22 AC 19 ms
10,904 KB
testcase_23 AC 14 ms
9,380 KB
testcase_24 AC 13 ms
9,392 KB
testcase_25 AC 6 ms
5,888 KB
testcase_26 AC 10 ms
7,800 KB
testcase_27 AC 23 ms
12,228 KB
testcase_28 AC 13 ms
9,440 KB
testcase_29 AC 13 ms
9,368 KB
testcase_30 AC 848 ms
198,860 KB
testcase_31 AC 872 ms
198,952 KB
testcase_32 AC 860 ms
198,952 KB
testcase_33 AC 853 ms
198,616 KB
testcase_34 AC 853 ms
197,808 KB
testcase_35 AC 883 ms
198,916 KB
testcase_36 AC 831 ms
193,548 KB
testcase_37 AC 827 ms
193,664 KB
testcase_38 AC 852 ms
198,200 KB
testcase_39 AC 865 ms
198,412 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 864 ms
198,872 KB
testcase_47 AC 859 ms
198,536 KB
testcase_48 AC 854 ms
198,948 KB
testcase_49 AC 757 ms
183,484 KB
testcase_50 AC 839 ms
197,236 KB
testcase_51 AC 855 ms
198,880 KB
testcase_52 AC 819 ms
198,984 KB
testcase_53 AC 810 ms
195,436 KB
testcase_54 AC 822 ms
199,000 KB
testcase_55 AC 827 ms
198,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, x; cin >> n >> x;
  if (n == 1) {
    cout << "B\n";
    return 0;
  }
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<int> l(n, 0), r(n, 0);
  REP(i, n) {
    int sum = a[i], j = i + 1;
    while (j < n && sum + a[j] <= x) sum += a[j++];
    l[i] = j - i;
  }
  REP(i, n) {
    int sum = a[i], j = i - 1;
    while (j >= 0 && sum + a[j] <= x) sum += a[j--];
    r[i] = i - j;
  }
  vector<vector<int> > dp_l(n, vector<int>(n, 0)), dp_r(n, vector<int>(n, 0));
  FOR(len, 2, n + 1) {
    REP(i, n) {
      int j = i + len - 1;
      if (j >= n) break;
      int chou = min(len - 1, l[i]);
      if (dp_r[i + 1][j] - (i + chou + 1 >= n ? 0 : dp_r[i + chou + 1][j]) != chou) {
        dp_l[i][j] = dp_l[i][j - 1] + 1;
        dp_r[i][j] = dp_r[i + 1][j] + 1;
        continue;
      }
      chou = min(len - 1, r[j]);
      if (dp_l[i][j - 1] - (j - chou - 1 < 0 ? 0 : dp_l[i][j - chou - 1]) != chou) {
        dp_l[i][j] = dp_l[i][j - 1] + 1;
        dp_r[i][j] = dp_r[i + 1][j] + 1;
        continue;
      }
      dp_l[i][j] = dp_l[i][j - 1];
      dp_r[i][j] = dp_r[i + 1][j];
    }
  }
  // REP(i, n) FOR(j, i, n) cout << i << ' ' << j << " : " << dp_r[i][j] << '\n';
  cout << (dp_l[0][n - 1] - dp_l[0][n - 2] == 1 ? "A\n" : "B\n");
  return 0;
}
0