結果
問題 | No.973 余興 |
ユーザー | amaridekinai |
提出日時 | 2020-01-17 23:16:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,815 bytes |
コンパイル時間 | 1,469 ms |
コンパイル使用メモリ | 167,696 KB |
実行使用メモリ | 204,212 KB |
最終ジャッジ日時 | 2023-09-08 07:13:41 |
合計ジャッジ時間 | 12,874 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 439 ms
204,212 KB |
testcase_01 | AC | 481 ms
199,684 KB |
testcase_02 | AC | 433 ms
200,012 KB |
testcase_03 | AC | 435 ms
199,888 KB |
testcase_04 | AC | 443 ms
199,756 KB |
testcase_05 | AC | 486 ms
199,756 KB |
testcase_06 | AC | 499 ms
199,828 KB |
testcase_07 | AC | 457 ms
199,752 KB |
testcase_08 | AC | 485 ms
199,828 KB |
testcase_09 | AC | 458 ms
199,696 KB |
testcase_10 | AC | 451 ms
199,876 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll N,X; vector<ll> a; int dp[5010][5010][2]; //閉じた区間[l,r]について考える bool rec(ll l, ll r, bool turn){ int c = 0; if(turn){ c = 1;} if( dp[l][r][c] != -1){ return dp[l][r][c];} if( r-l == 0){ //1つのみが残っている時 このターンに回ってきた方が負ける return !turn; } else{ ll left = l; ll right = r; ll res1 = 0,res2 = 0; if( turn ){ // Aのターンの時 while(left < r && res1+a[left] <= X){ res1 += a[left]; left++; if( rec(left,r,!turn) == true ){ dp[l][r][1] = 1; return true;} //一つでもtrueが返せる瞬間があったら、Aは勝てる } while(right > l && res2+a[right] <= X){ res2 += a[right]; right--; if( rec(l,right,!turn) == true ){ dp[l][r][1] = 1; return true;} } dp[l][r][1] = 0; return false; } else{ while(left < r && res1+a[left] <= X){ res1 += a[left]; left++; if( rec(left,r,!turn) == false ){ dp[l][r][0] = 0;return false;} } while(right > l && res2+a[right] <= X){ res2 += a[right]; right--; if( rec(l,right,!turn) == false){ dp[l][r][0] = 0; return false;} } dp[l][r][0] = 1; return true; } } } int main(){ cin >> N >> X; a.resize(N); for(ll i = 0; i < N; i++){ cin >> a[i];} for(int i = 0; i < 5010; i++){ for(int j = 0; j < 5010; j++){ dp[i][j][0] = -1; dp[i][j][1] = -1; } } bool res = rec(0,N-1,true); if( res ){ cout << "A" << endl;} else{ cout <<"B" << endl;} return 0; }