結果

問題 No.973 余興
ユーザー ransewhaleransewhale
提出日時 2020-01-17 23:18:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 4,000 ms
コード長 1,193 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 165,204 KB
実行使用メモリ 124,164 KB
最終ジャッジ日時 2023-09-08 07:17:36
合計ジャッジ時間 16,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 422 ms
124,044 KB
testcase_01 AC 422 ms
123,968 KB
testcase_02 AC 415 ms
123,908 KB
testcase_03 AC 428 ms
123,964 KB
testcase_04 AC 433 ms
123,976 KB
testcase_05 AC 434 ms
123,980 KB
testcase_06 AC 432 ms
124,040 KB
testcase_07 AC 447 ms
123,880 KB
testcase_08 AC 440 ms
123,940 KB
testcase_09 AC 447 ms
123,972 KB
testcase_10 AC 423 ms
124,012 KB
testcase_11 AC 137 ms
123,904 KB
testcase_12 AC 137 ms
123,896 KB
testcase_13 AC 138 ms
123,928 KB
testcase_14 AC 137 ms
123,892 KB
testcase_15 AC 44 ms
123,892 KB
testcase_16 AC 44 ms
123,960 KB
testcase_17 AC 40 ms
124,060 KB
testcase_18 AC 42 ms
123,944 KB
testcase_19 AC 42 ms
123,896 KB
testcase_20 AC 40 ms
123,936 KB
testcase_21 AC 44 ms
123,880 KB
testcase_22 AC 43 ms
123,880 KB
testcase_23 AC 40 ms
123,888 KB
testcase_24 AC 40 ms
123,840 KB
testcase_25 AC 37 ms
124,108 KB
testcase_26 AC 40 ms
123,920 KB
testcase_27 AC 45 ms
123,892 KB
testcase_28 AC 41 ms
123,932 KB
testcase_29 AC 40 ms
123,836 KB
testcase_30 AC 335 ms
123,868 KB
testcase_31 AC 336 ms
123,952 KB
testcase_32 AC 335 ms
123,964 KB
testcase_33 AC 333 ms
123,952 KB
testcase_34 AC 336 ms
123,916 KB
testcase_35 AC 334 ms
123,952 KB
testcase_36 AC 326 ms
123,952 KB
testcase_37 AC 328 ms
124,016 KB
testcase_38 AC 334 ms
123,912 KB
testcase_39 AC 336 ms
123,884 KB
testcase_40 AC 33 ms
123,832 KB
testcase_41 AC 33 ms
124,164 KB
testcase_42 AC 33 ms
124,116 KB
testcase_43 AC 33 ms
123,960 KB
testcase_44 AC 34 ms
123,976 KB
testcase_45 AC 33 ms
123,936 KB
testcase_46 AC 336 ms
123,956 KB
testcase_47 AC 335 ms
124,104 KB
testcase_48 AC 334 ms
123,916 KB
testcase_49 AC 306 ms
124,036 KB
testcase_50 AC 332 ms
123,924 KB
testcase_51 AC 337 ms
123,904 KB
testcase_52 AC 337 ms
124,104 KB
testcase_53 AC 327 ms
123,992 KB
testcase_54 AC 336 ms
124,104 KB
testcase_55 AC 335 ms
123,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int dp[5555][5555];
ll s[5555];

int main(void){
	int i,j,n;
	ll a,x;
	cin >> n >> x;
	fill(dp[0],dp[5555],-1);
	for(i=0; i<n; ++i){
		cin >> a;
		s[i+1] = s[i]+a;
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(!(j+i<n)){
				break;
			}
			if(dp[j][j+i]<0 && dp[j+i][j]<0){
				dp[j][j+i+1] = max(j+i,dp[j][j+i+1]);
				if(j){
					if(dp[j+i][j-1]<0){
						dp[j+i][j-1] = j;
					}else{
						dp[j+i][j-1] = min(j,dp[j+i][j-1]);
					}
				}
			}
			if(!(dp[j][j+i]<0)){
				if(s[j+i+2]-s[dp[j][j+i]+1]<=x){
					dp[j][j+i+1] = max(dp[j][j+i+1],dp[j][j+i]);
				}
			}
			if((!(dp[j+i][j]<0)) && j){
				if(s[dp[j+i][j]] - s[j-1]<=x){
					if(dp[j+i][j-1]<0){
						dp[j+i][j-1] = dp[j+i][j];
					}else{
						dp[j+i][j-1] = min(dp[j+i][j-1],dp[j+i][j]);
					}
				}
			}
		}
	}
	cout << ((dp[0][n-1]<0 && dp[n-1][0]<0)?"B":"A") << endl;
	return 0;
}
0