結果

問題 No.973 余興
ユーザー chocoruskchocorusk
提出日時 2020-01-17 22:20:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,722 ms / 4,000 ms
コード長 1,329 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 108,756 KB
実行使用メモリ 235,996 KB
最終ジャッジ日時 2023-09-08 04:06:39
合計ジャッジ時間 47,159 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,665 ms
235,764 KB
testcase_01 AC 1,680 ms
235,752 KB
testcase_02 AC 1,722 ms
235,736 KB
testcase_03 AC 1,688 ms
235,632 KB
testcase_04 AC 1,658 ms
235,808 KB
testcase_05 AC 1,709 ms
235,748 KB
testcase_06 AC 1,696 ms
235,756 KB
testcase_07 AC 1,676 ms
235,660 KB
testcase_08 AC 1,689 ms
235,560 KB
testcase_09 AC 1,658 ms
235,740 KB
testcase_10 AC 1,601 ms
231,616 KB
testcase_11 AC 359 ms
123,840 KB
testcase_12 AC 358 ms
123,884 KB
testcase_13 AC 347 ms
123,452 KB
testcase_14 AC 347 ms
123,464 KB
testcase_15 AC 69 ms
35,740 KB
testcase_16 AC 71 ms
37,884 KB
testcase_17 AC 43 ms
28,440 KB
testcase_18 AC 55 ms
32,064 KB
testcase_19 AC 57 ms
32,040 KB
testcase_20 AC 43 ms
28,228 KB
testcase_21 AC 68 ms
35,692 KB
testcase_22 AC 69 ms
35,680 KB
testcase_23 AC 56 ms
32,116 KB
testcase_24 AC 56 ms
31,968 KB
testcase_25 AC 28 ms
23,800 KB
testcase_26 AC 44 ms
28,252 KB
testcase_27 AC 80 ms
38,992 KB
testcase_28 AC 58 ms
32,064 KB
testcase_29 AC 56 ms
31,880 KB
testcase_30 AC 1,109 ms
235,744 KB
testcase_31 AC 1,112 ms
235,748 KB
testcase_32 AC 1,135 ms
235,776 KB
testcase_33 AC 1,107 ms
235,916 KB
testcase_34 AC 1,116 ms
235,308 KB
testcase_35 AC 1,113 ms
235,740 KB
testcase_36 AC 1,078 ms
232,936 KB
testcase_37 AC 1,101 ms
233,096 KB
testcase_38 AC 1,108 ms
235,396 KB
testcase_39 AC 1,118 ms
235,552 KB
testcase_40 AC 2 ms
5,324 KB
testcase_41 AC 2 ms
5,572 KB
testcase_42 AC 2 ms
5,324 KB
testcase_43 AC 2 ms
5,392 KB
testcase_44 AC 2 ms
5,332 KB
testcase_45 AC 4 ms
8,500 KB
testcase_46 AC 979 ms
235,756 KB
testcase_47 AC 983 ms
235,796 KB
testcase_48 AC 974 ms
235,756 KB
testcase_49 AC 929 ms
225,588 KB
testcase_50 AC 983 ms
235,064 KB
testcase_51 AC 998 ms
235,748 KB
testcase_52 AC 1,149 ms
235,996 KB
testcase_53 AC 1,128 ms
233,824 KB
testcase_54 AC 1,145 ms
235,808 KB
testcase_55 AC 1,111 ms
235,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dp[5050][5050];
int s1[5050][5050];
int s2[5050][5050];
ll a[5050];
ll s[5050];
int n;
ll x;

int main()
{
	int n;
	ll x;
	cin>>n>>x;
	for(int i=0; i<n; i++){
		cin>>a[i];
		s[i+1]=s[i]+a[i];
	}
	for(int i=0; i<n; i++) dp[i][i]=1;
	for(int d=1; d<n; d++){
		for(int i=0; i+d<n; i++){
			int l=i, r=i+d;
			int k=upper_bound(s, s+n+1, s[l]+x)-s;
			k-=2;
			k=min(k, r-1);
			if(s1[l+1][r]-s1[k+2][r]>0){
				dp[l][r]=0;
				s1[l][r]=s1[l+1][r]+dp[l][r];
				s2[l][r]=s2[l][r-1]+dp[l][r];
				continue;
			}
			k=lower_bound(s, s+n+1, s[r+1]-x)-s;
			k=max(k, l+1);
			if(s2[l][r-1]-s2[l][k-2]>0){
				dp[l][r]=0;
			}else{
				dp[l][r]=1;
			}
			s1[l][r]=s1[l+1][r]+dp[l][r];
			s2[l][r]=s2[l][r-1]+dp[l][r];
		}
	}
	if(dp[0][n-1]) cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}
0