結果
| 問題 | No.973 余興 |
| コンテスト | |
| ユーザー |
Dente
|
| 提出日時 | 2020-01-17 22:06:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,352 bytes |
| 記録 | |
| コンパイル時間 | 1,543 ms |
| コンパイル使用メモリ | 168,576 KB |
| 実行使用メモリ | 205,828 KB |
| 最終ジャッジ日時 | 2024-06-25 20:25:27 |
| 合計ジャッジ時間 | 12,108 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | TLE * 1 -- * 53 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
#define MAX_N 5000
int n;
ll x;
ll a[MAX_N];
int dp[MAX_N][MAX_N][2];
bool rec(int l, int r, bool A){
if(dp[l][r][A] != -1) return dp[l][r][A];
if(l == r) return A;
ll now = 0;
if(A){
bool res = false;
for(int i = l + 1; i <= r; i++){
if(now + a[i] > x) break;
res |= rec(i, r, !A);
}
now = 0;
for(int i = r - 1; i >= l; i--){
if(now + a[i] > x) break;
res |= rec(l, i, !A);
}
return dp[l][r][A] = res;
}else{
bool res = false;
for(int i = l + 1; i <= r; i++){
if(now + a[i] > x) break;
res |= !rec(i, r, !A);
}
now = 0;
for(int i = r - 1; i >= l; i--){
if(now + a[i] > x) break;
res |= !rec(l, i, !A);
}
return dp[l][r][A] = !res;
}
}
signed main(){
cin >> n >> x;
REP(i,n){
cin >> a[i];
}
memset(dp, -1, sizeof(dp));
if(rec(0, n, true)){
cout << "A" << endl;
}else{
cout << "B" << endl;
}
return 0;
}
Dente