結果

問題 No.973 余興
ユーザー どらら
提出日時 2020-01-17 23:19:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 902 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 85,236 KB
実行使用メモリ 818,176 KB
最終ジャッジ日時 2024-06-26 00:34:42
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other MLE * 1 -- * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long

using namespace std;

int N, X;
vector<int> v;
map<pair<int,int>,bool> memo;

bool solve(int l, int r) {
    if(memo.count(make_pair(l,r)) > 0) return memo[make_pair(l,r)];
    if(l==r){
        return memo[make_pair(l,r)] = false;
    }
    bool canwin = false;
    ll sum = 0;
    for(int i=l; i<r; i++){
        sum += v[i];
        if(sum > X) break;
        if(!solve(i, r)) canwin = true;
    }
    sum = 0;
    for(int i=r; i>l; i--){
        sum += v[i];
        if(sum > X) break;
        if(!solve(l, i)) canwin = true;
    }
    
    return memo[make_pair(l,r)] = canwin;
}

int main(){
    cin >> N >> X;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }
    
    if(solve(0, N-1)) cout << "A" << endl;
    else cout << "B" << endl;
    
    return 0;
}
0