結果

問題 No.973 余興
ユーザー amaridekinaiamaridekinai
提出日時 2020-01-17 23:13:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 167,412 KB
実行使用メモリ 200,000 KB
最終ジャッジ日時 2023-09-08 07:03:07
合計ジャッジ時間 13,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
199,740 KB
testcase_01 AC 269 ms
199,660 KB
testcase_02 AC 268 ms
199,792 KB
testcase_03 AC 269 ms
199,656 KB
testcase_04 AC 269 ms
199,712 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 259 ms
199,720 KB
testcase_11 AC 117 ms
199,572 KB
testcase_12 AC 118 ms
199,568 KB
testcase_13 WA -
testcase_14 AC 118 ms
199,544 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 56 ms
199,528 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 58 ms
199,464 KB
testcase_23 AC 58 ms
199,460 KB
testcase_24 AC 57 ms
199,496 KB
testcase_25 AC 57 ms
199,420 KB
testcase_26 AC 58 ms
199,680 KB
testcase_27 AC 59 ms
199,508 KB
testcase_28 WA -
testcase_29 AC 56 ms
199,528 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 267 ms
199,688 KB
testcase_35 AC 270 ms
199,824 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 266 ms
199,720 KB
testcase_39 WA -
testcase_40 AC 56 ms
199,488 KB
testcase_41 AC 56 ms
199,456 KB
testcase_42 AC 57 ms
199,444 KB
testcase_43 WA -
testcase_44 AC 57 ms
199,488 KB
testcase_45 WA -
testcase_46 AC 270 ms
199,828 KB
testcase_47 WA -
testcase_48 AC 267 ms
199,652 KB
testcase_49 WA -
testcase_50 AC 268 ms
199,656 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 262 ms
199,788 KB
testcase_54 AC 268 ms
199,956 KB
testcase_55 AC 267 ms
199,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll N,X;

vector<ll> a;

int dp[5010][5010][2];

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){ 
       left++;
      if( rec(left,r,!turn) == true ){ dp[l][r][1] = 1; return true;}
       //一つでもtrueが返せる瞬間があったら、Aは勝てる
       
    }
      
      while(right > l && res2+a[right] <= X){
        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){
        left++;
        if( rec(left,r,!turn) == false ){ dp[l][r][0] = 0;return false;}
        
      }
      
      while(right > l && res2+a[right] <= X){
        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;
}
0