結果
| 問題 |
No.973 余興
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2020-01-17 23:25:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,120 bytes |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 77,160 KB |
| 実行使用メモリ | 56,348 KB |
| 最終ジャッジ日時 | 2024-06-26 01:00:02 |
| 合計ジャッジ時間 | 10,501 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 11 TLE * 1 -- * 42 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long
using namespace std;
int N, X;
vector<int> v;
char memo[5005][5005];
bool solve(int l, int r) {
if(memo[l][r] != '-'){
if(memo[l][r] == 'l') return false;
else return true;
}
if(l==r){
return false;
}
bool canwin = false;
ll sum = 0;
for(int i=l; i<r; i++){
sum += v[i];
if(sum > X) break;
if(!solve(i+1, r)) canwin = true;
}
sum = 0;
for(int i=r; i>l; i--){
sum += v[i];
if(sum > X) break;
if(!solve(l, i-1)) canwin = true;
}
if(canwin){
memo[l][r] = 'w';
return true;
}else{
memo[l][r] = 'l';
return false;
}
}
int main(){
cin >> N >> X;
for(int i=0; i<N; i++){
int a;
cin >> a;
v.push_back(a);
}
for(int i=0; i<5005; i++){
for(int j=0; j<5005; j++){
memo[i][j] = '-';
}
}
if(solve(0, N-1)) cout << "A" << endl;
else cout << "B" << endl;
return 0;
}
どらら