Submission #883146

#TimeUsernameProblemLanguageResultExecution timeMemory
883146serifefedartarBali Sculptures (APIO15_sculpture)C++17
100 / 100
91 ms756 KiB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 3000;

vector<ll> arr;
ll pref[MAXN], N, A, B; 
pair<ll,ll> dp[MAXN];
bool check(ll mid) {
	dp[0] = {0, 0};
	for (int i = 1; i < MAXN; i++)
		dp[i] = {1e12, -1e12};

	for (int i = 1; i <= N; i++) {
		for (int j = i-1; j >= 0; j--) {
			if ((mid | (pref[i] - pref[j])) == mid)
				dp[i] = {min(dp[i].f, dp[j].f + 1), max(dp[i].s, dp[j].s + 1)};
		}
	}

	return (B >= dp[N].f && A <= dp[N].s);
}

void solve1() {
	ll ans = (1LL << 42) - 1;
	for (int bit = 41; bit >= 0; bit--) {
		bool ch = check(ans ^ (1LL << bit));
		if (ch)
			ans ^= (1LL << bit);
	}
	cout << ans << "\n";
}

void solve2() {

}

int main() {
	cin >> N >> A >> B;

	arr = vector<ll>(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> arr[i];
		pref[i] = pref[i-1] + arr[i];
	}
	
	solve1();
}
#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...