Submission #99473

#TimeUsernameProblemLanguageResultExecution timeMemory
99473Shafin666Bali Sculptures (APIO15_sculpture)C++14
100 / 100
441 ms31996 KiB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
typedef long double ld;
using namespace std;

int n, a, b;
ll num[2005], pre[2050];
ll dp[2005], dp2[2005][2005];
ll bit = 43, mask;

ll c(int i, int j) {
	return pre[j] - pre[i-1];
}

void can(int x) {
	mask ^= (1LL << x);

	for(int i = 1; i <= n; i++) {
		dp[i] = 1e18+7;

		for(int j = 0; j < i; j++) {
			if((mask | c(j+1, i)) == mask) dp[i] = min(dp[i], dp[j]+1);
		}
	}
	if(dp[n] > b) mask |= (1LL << x);
}

void can2(int x) {
	mask ^= (1LL << x);

	memset(dp2, 0, sizeof dp2);
	dp2[0][0] = 1;

	for(int k = 1; k <= n; k++) {
		for(int i = 1;  i <= n; i++) {
			for(int j = 0; j < i; j++) {
				if((mask | c(j+1, i)) == mask) dp2[k][i] |= dp2[k-1][j];
			}
		}
	}

	for(int i = a; i <= b; i++) if(dp2[i][n]) return;
	mask |= (1LL << x);
}

int main() 
{
	cin >> n >> a >> b;

	ll mn = 1e18+7;

	for(int i = 1; i <= n; i++) cin >> num[i];
	for(int i = 1; i <= n; i++) pre[i] = pre[i-1] + num[i];

	for(int i = 0; i <= bit; i++) mask |= (1LL << i);

	for(int i = bit; i >= 0; i--) (a == 1)? can(i) : can2(i);

	cout << mask << endl;

	return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:53:5: warning: unused variable 'mn' [-Wunused-variable]
  ll mn = 1e18+7;
     ^~
#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...