結果
問題 |
No.973 余興
|
ユーザー |
![]() |
提出日時 | 2020-01-17 23:27:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,172 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 77,216 KB |
実行使用メモリ | 35,056 KB |
最終ジャッジ日時 | 2024-06-26 01:07:40 |
合計ジャッジ時間 | 9,637 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; if(canwin) break; } 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) break; } 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; }