結果

問題 No.973 余興
ユーザー kzyKTkzyKT
提出日時 2020-01-17 21:59:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,972 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 144,868 KB
実行使用メモリ 199,476 KB
最終ジャッジ日時 2023-09-08 02:52:08
合計ジャッジ時間 15,919 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 372 ms
199,184 KB
testcase_01 AC 365 ms
199,348 KB
testcase_02 AC 363 ms
199,188 KB
testcase_03 AC 361 ms
199,268 KB
testcase_04 WA -
testcase_05 AC 372 ms
199,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 374 ms
199,280 KB
testcase_09 AC 377 ms
199,348 KB
testcase_10 WA -
testcase_11 AC 151 ms
199,072 KB
testcase_12 AC 152 ms
199,132 KB
testcase_13 WA -
testcase_14 AC 149 ms
199,024 KB
testcase_15 AC 64 ms
198,868 KB
testcase_16 AC 65 ms
198,772 KB
testcase_17 AC 59 ms
198,844 KB
testcase_18 AC 62 ms
198,856 KB
testcase_19 AC 62 ms
198,884 KB
testcase_20 AC 60 ms
198,852 KB
testcase_21 AC 65 ms
198,908 KB
testcase_22 AC 65 ms
198,828 KB
testcase_23 AC 63 ms
198,776 KB
testcase_24 AC 61 ms
198,872 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 67 ms
198,900 KB
testcase_28 AC 62 ms
198,860 KB
testcase_29 AC 62 ms
198,900 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 323 ms
199,216 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 324 ms
199,344 KB
testcase_39 AC 328 ms
199,260 KB
testcase_40 AC 52 ms
198,860 KB
testcase_41 AC 52 ms
198,716 KB
testcase_42 AC 52 ms
198,776 KB
testcase_43 AC 52 ms
198,780 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 331 ms
199,268 KB
testcase_49 AC 308 ms
199,152 KB
testcase_50 WA -
testcase_51 AC 330 ms
199,348 KB
testcase_52 AC 334 ms
199,292 KB
testcase_53 WA -
testcase_54 AC 332 ms
199,260 KB
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;


int dp[2][5001][5001],m,a[5555];
int dfs(int l, int r, int t,int k,ll sum) {
  if(dp[t][l][r]!=-1) return dp[t][l][r];
  if(l==r) return t^1;
  int s=t^1,z;
  if(k==-1) {
    if(sum+a[l]<=m) {
      z=dfs(l+1,r,t,0,sum+a[l]);
      if(z==t) s=z;
      z=dfs(l+1,r,t^1,-1,0);
      if(z==t) s=z;
    }
    if(sum+a[r]<=m) {
      z=dfs(l,r-1,t,1,sum+a[r]);
      if(z==t) s=z;
      z=dfs(l,r-1,t^1,-1,0);
      if(z==t) s=z;
    }
  } else if(k==0) {
    if(sum+a[l]<=m) {
      int z=dfs(l+1,r,t,0,sum+a[l]);
      if(z==t) s=z;
      z=dfs(l+1,r,t^1,-1,0);
      if(z==t) s=z;
    }
  } else {
    if(sum+a[r]<=m) {
      int z=dfs(l,r-1,t,1,sum+a[r]);
      if(z==t) s=z;
      z=dfs(l,r-1,t^1,-1,0);
      if(z==t) s=z;
    }
  }
  dp[t][l][r]=s;
  return s;
}

void Main() {
  ll n;
  cin >> n >> m;
  rep(i,n) cin >> a[i];
  memset(dp,-1,sizeof(dp));
  if(dfs(0,n-1,1,-1,0)) pr("A");
  else pr("B");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0