結果
| 問題 | 
                            No.973 余興
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Dente
                         | 
                    
| 提出日時 | 2020-01-17 22:22:45 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,363 bytes | 
| コンパイル時間 | 1,617 ms | 
| コンパイル使用メモリ | 166,680 KB | 
| 実行使用メモリ | 209,920 KB | 
| 最終ジャッジ日時 | 2024-06-25 21:22:41 | 
| 合計ジャッジ時間 | 12,213 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / 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 + 1][MAX_N + 1][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; i <= r; i++){
            if(now + a[i] > x) break;
            res |= rec(i + 1, r, !A);
        }
        now = 0;
        for(int i = r; i >= l; i--){
            if(now + a[i] > x) break;
            res |= rec(l, i - 1, !A);
        }
        return dp[l][r][A] = res;
    }else{
        bool res = false;
        for(int i = l; i <= r; i++){
            if(now + a[i] > x) break;
            res |= !rec(i + 1, r, !A);
        }
        now = 0;
        for(int i = r; i >= l; i--){
            if(now + a[i] > x) break;
            res |= !rec(l, i - 1, !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 - 1, true)){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
    return 0;
}
            
            
            
        
            
Dente