Submission #338930

#TimeUsernameProblemLanguageResultExecution timeMemory
338930ogibogi2004Bali Sculptures (APIO15_sculpture)C++14
100 / 100
139 ms4480 KiB
#include<bits/stdc++.h>
using namespace std;
#define try ico
#define ll long long
const ll MAXN=2048;
ll y[MAXN],n,a,b;
ll depth[MAXN];
bool dp[MAXN][MAXN];
bool try(ll mask)
{
	memset(dp,0,sizeof(dp));
	dp[1][0]=1;
	for(int i=1;i<=n;i++)
	{
		ll sum=0;
		for(int j=i;j<=n;j++)
		{
			sum+=y[j];
			if((mask&sum)==sum&&(mask|sum)==mask)
			{
				for(int l=0;l<=n;l++)
				{
					dp[j+1][l+1]|=dp[i][l];
				}
			}
		}
	}
	for(ll i=a;i<=b;i++)
	{
		if(dp[n+1][i])
		{
			return 1;
		}
	}
	return 0;
}
bool try1(ll mask)
{
	queue<ll>q;
	q.push(1);
	depth[1]=0;
	for(int i=2;i<=n+1;i++)depth[i]=n+200;
	while(!q.empty())
	{
		ll u=q.front();q.pop();
		ll sum=0;
		for(ll j=u;j<=n;j++)
		{
			sum+=y[j];
			if((mask&sum)==sum&&(mask|sum)==mask)
			{
				if(depth[j+1]<=depth[u]+1)continue;
				depth[j+1]=depth[u]+1;
				q.push(j+1);
			}
		}
	}
	if(depth[n+1]<=b)return 1;
	return 0;
}
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>y[i];
	}
	if(a==1)
	{
		ll mask=(1ll<<60)-1;
		for(ll i=59;i>=0;i--)
		{
			if(try1(mask-(1ll<<i)))
			{
				mask-=(1ll<<i);
			}
		}
		cout<<mask<<endl;
		return 0;
	}
	ll mask=(1ll<<60)-1;
	for(ll i=59;i>=0;i--)
	{
		if(try(mask-(1ll<<i)))
		{
			mask-=(1ll<<i);
		}
	}
	cout<<mask<<endl;
return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...