結果

問題 No.973 余興
ユーザー kotatsugamekotatsugame
提出日時 2020-01-17 23:12:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,959 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 85,196 KB
実行使用メモリ 33,308 KB
最終ジャッジ日時 2023-09-08 07:01:19
合計ジャッジ時間 11,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:52:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   52 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N;
long A[5000],X,S[5001];
main()
{
	cin>>N>>X;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S[i+1]=S[i]+A[i];
	}
	auto f=[](bool a,bool b){return a&&b;};
	auto g=[](bool a,bool b){return b;};
	vector<segtree<bool> >dpL(N+1,segtree<bool>(N+1,true,f,g));
	vector<segtree<bool> >dpR(N+1,segtree<bool>(N+1,true,f,g));
	for(int i=0;i<N;i++)
	{
		dpL[i].update(i+1,false);
		dpR[i+1].update(i,false);
	}
	for(int k=2;k<=N;k++)
	{
		for(int i=0;i+k<=N;i++)
		{
			int l=i,r=i+k;
			bool now=false;
			{
				int L=l+1,R=r+1;
				while(R-L>1)
				{
					int M=(L+R)/2;
					if(S[M]-S[l]<=X)L=M;
					else R=M;
				}
				if(!dpR[r].query(l+1,R))now=true;
			}
			{
				int L=l-1,R=r-1;
				while(R-L>1)
				{
					int M=(L+R)/2;
					if(S[r]-S[M]<=X)R=M;
					else L=M;
				}
				if(!dpL[l].query(R,r))now=true;
			}
			dpL[l].update(r,now);
			dpR[r].update(l,now);
		}
	}
	cout<<(dpL[0].query(N,N+1)?"A":"B")<<endl;
}
0