Submission #469967

#TimeUsernameProblemLanguageResultExecution timeMemory
469967luciocfBali Sculptures (APIO15_sculpture)C++14
71 / 100
1086 ms736 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 2e3+10;
const int inf = 1e9;

int n;
int a[maxn];

ll pref[maxn];

int dp[maxn][maxn];

bool bad(ll s, ll mask, int pos)
{
	for (int i = 60; i >= pos; i--)
		if ((!(mask&(1ll<<i))) && (s&(1ll<<i)))
			return 1;

	return 0;
}

int main(void)
{
	int A, B;
	scanf("%d %d %d", &n, &A, &B);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);

		pref[i] = pref[i-1] + 1ll*a[i]; 
	}

	if (A != 1)
	{
		ll mask = 0;

		for (int b = 60; b >= 0; b--)
		{
			dp[0][0] = 1;

			for (int i = 0; i <= n; i++)
				for (int j = 1; j <= n; j++)
					dp[i][j] = 0;

			for (int k = 1; k <= n; k++)
			{
				for (int i = 1; i <= n; i++)
				{
					for (int j = i; j >= 1; j--)
					{
						ll s = pref[i] - pref[j-1];

						if (dp[k-1][j-1] && !bad(s, mask, b))
							dp[k][i] = 1;
					}
				}
			}


			bool ok = 0;
			for (int i = A; i <= B; i++)
				if (dp[i][n])
					ok = 1;

			if (!ok) mask += (1ll<<b);
		}

		printf("%lld\n", mask);

		return 0;
	}


	ll mask = 0;

	for (int b = 60; b >= 0; b--)
	{
		for (int i = 1; i <= n; i++)
			dp[0][i] = inf;

		for (int i = 1; i <= n; i++)
		{
			for (int j = i; j >= 1; j--)
			{
				ll s = pref[i] - pref[j-1];

				if (dp[0][j-1] != inf && !bad(s, mask, b))
					dp[0][i] = min(dp[0][i], dp[0][j-1] + 1);
			}
		}

		if (dp[0][n] > B) mask += (1ll<<b);
	}

	printf("%lld\n", mask);
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d %d %d", &n, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
#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...