結果

問題 No.973 余興
ユーザー chocoruskchocorusk
提出日時 2020-01-17 22:15:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,435 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 110,108 KB
実行使用メモリ 204,928 KB
最終ジャッジ日時 2024-06-25 20:56:53
合計ジャッジ時間 14,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28 WA * 26
権限があれば一括ダウンロードができます

ソースコード

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 solve(int l, int r){
	if(dp[l][r]!=-1) return dp[l][r];
	if(l==r){
		dp[l][r]=1;
		s1[l][r]=s2[l][r]=1;
		return 1;
	}
	solve(l+1, r);
	solve(l, r-1);
	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];
		return dp[l][r];
	}
	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];
	return dp[l][r];
}
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++) for(int j=i; j<n; j++) dp[i][j]=-1;
	solve(0, n-1);
	if(dp[0][n-1]) cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}
0