結果
| 問題 | 
                            No.973 余興
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-01-20 15:48:14 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 948 bytes | 
| コンパイル時間 | 1,893 ms | 
| コンパイル使用メモリ | 192,172 KB | 
| 最終ジャッジ日時 | 2025-01-08 20:19:57 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 16 WA * 14 TLE * 24 | 
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int memo[5005][5005][2];
long long a[5005], sum[5005];
int n, x;
bool rec (int left, int right, int turn) {
  if (left > right) return true;
  if (left == right) return false;
  if (memo[left][right][turn] != -1) return memo[left][right][turn];
  int& res = memo[left][right][turn];
  res = false;
  if (turn == 0) {
    for (int i = left; i <= right; i++) {
      if (sum[i] - sum[left - 1] > x) break;
      if (!rec(i + 1, right, 1)) res = true;
    }
  } else {
    for (int i = right; i >= left; i--) {
      if (sum[right] - sum[i - 1] > x) break;
      if (!rec(left, i - 1, 0)) res = true;
    }
  }
  return res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  memset(memo, -1, sizeof(memo));
  cout << (rec(1, n, 0) ? "A\n" : "B\n");
  return 0;
}