結果

問題 No.973 余興
ユーザー leaf_1415leaf_1415
提出日時 2020-01-18 04:06:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,054 ms / 4,000 ms
コード長 1,340 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 60,912 KB
実行使用メモリ 287,412 KB
最終ジャッジ日時 2023-09-08 15:28:28
合計ジャッジ時間 32,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,047 ms
284,508 KB
testcase_01 AC 1,044 ms
285,912 KB
testcase_02 AC 1,046 ms
285,616 KB
testcase_03 AC 1,043 ms
285,608 KB
testcase_04 AC 1,042 ms
285,944 KB
testcase_05 AC 1,054 ms
285,784 KB
testcase_06 AC 1,048 ms
285,616 KB
testcase_07 AC 1,048 ms
285,596 KB
testcase_08 AC 1,038 ms
284,136 KB
testcase_09 AC 1,046 ms
285,660 KB
testcase_10 AC 1,007 ms
278,688 KB
testcase_11 AC 333 ms
145,964 KB
testcase_12 AC 334 ms
146,884 KB
testcase_13 AC 328 ms
146,456 KB
testcase_14 AC 329 ms
146,628 KB
testcase_15 AC 50 ms
52,296 KB
testcase_16 AC 51 ms
52,452 KB
testcase_17 AC 33 ms
41,744 KB
testcase_18 AC 41 ms
47,036 KB
testcase_19 AC 41 ms
47,176 KB
testcase_20 AC 32 ms
41,636 KB
testcase_21 AC 49 ms
52,396 KB
testcase_22 AC 49 ms
52,268 KB
testcase_23 AC 41 ms
47,056 KB
testcase_24 AC 40 ms
46,988 KB
testcase_25 AC 22 ms
34,048 KB
testcase_26 AC 32 ms
41,688 KB
testcase_27 AC 57 ms
57,336 KB
testcase_28 AC 41 ms
47,180 KB
testcase_29 AC 40 ms
46,876 KB
testcase_30 AC 873 ms
285,676 KB
testcase_31 AC 878 ms
284,564 KB
testcase_32 AC 877 ms
284,636 KB
testcase_33 AC 884 ms
284,436 KB
testcase_34 AC 878 ms
284,076 KB
testcase_35 AC 867 ms
284,528 KB
testcase_36 AC 842 ms
279,576 KB
testcase_37 AC 850 ms
279,576 KB
testcase_38 AC 929 ms
284,056 KB
testcase_39 AC 862 ms
284,372 KB
testcase_40 AC 2 ms
5,448 KB
testcase_41 AC 2 ms
5,472 KB
testcase_42 AC 2 ms
5,432 KB
testcase_43 AC 2 ms
5,528 KB
testcase_44 AC 2 ms
5,440 KB
testcase_45 AC 4 ms
10,112 KB
testcase_46 AC 503 ms
284,792 KB
testcase_47 AC 514 ms
283,352 KB
testcase_48 AC 530 ms
283,384 KB
testcase_49 AC 471 ms
268,608 KB
testcase_50 AC 530 ms
282,476 KB
testcase_51 AC 508 ms
284,828 KB
testcase_52 AC 970 ms
283,380 KB
testcase_53 AC 958 ms
280,816 KB
testcase_54 AC 990 ms
284,828 KB
testcase_55 AC 981 ms
287,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint n, x;
llint a[5005], sum[5005];
llint dp[5005][5005], dpsum[5005][5005];

llint get(llint sl, llint sr, llint tl, llint tr)
{
	return dpsum[tl][tr] - dpsum[tl][sr-1] - dpsum[sl+1][tr] + dpsum[sl+1][sr-1];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	
	for(int l = n; l >= 1; l--){
		for(int r = 1; r <= n; r++){
			if(r-l < 0) continue;
			if(r-l == 0) dp[l][r] = 1;
			else{
				llint res = 0;
				llint p = upper_bound(sum, sum+n+1, sum[l-1]+x) - sum;
				if(p > r) res++;
				else res += get(p, r, l+1, r);
				
				//cout << l << " " << r << " " << p << " " << get(l+1, r, p, r) << endl;
				
				p = lower_bound(sum, sum+n+1, sum[r]-x) - sum;
				if(p < l) res++;
				else res += get(l, p, l, r-1);
				
				//cout << l << " " << r << " " << p << endl;
				
				if(res > 0) dp[l][r] = 0;
				else dp[l][r] = 1;
			}
			dpsum[l][r] = dpsum[l+1][r] + dpsum[l][r-1] - dpsum[l+1][r-1] + dp[l][r];
		}
	}
	
	/*for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout <<dp[i][j]<< " ";
		}
		cout << endl;
	}*/
	
	if(dp[1][n]) cout << "B" << endl;
	else cout << "A" << endl;
	
	return 0;
}
0