#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, A, B;
cin >> N >> A >> B;
vector<long long> Y(N + 1), prefix(N + 1, 0);
for (int i = 1; i <= N; i++) {
cin >> Y[i];
prefix[i] = prefix[i - 1] + Y[i];
}
// Try to greedily build answer bit by bit (from highest to lowest bit)
long long answer = 0;
for (int bit = 60; bit >= 0; bit--) {
long long candidate = answer; // keep current bits
// try to not set this bit
vector<vector<bool>> dp(N + 1, vector<bool>(B + 1, false));
dp[0][0] = true;
long long mask = candidate; // current bits fixed
for (int i = 1; i <= N; i++) {
for (int k = 1; k <= B; k++) {
for (int j = 0; j < i; j++) {
if (!dp[j][k - 1]) continue;
long long sum = prefix[i] - prefix[j];
if ((sum & ~mask) == 0) {
dp[i][k] = true;
break;
}
}
}
}
bool ok = false;
for (int x = A; x <= B; x++) {
if (dp[N][x]) {
ok = true;
break;
}
}
if (!ok) {
answer |= (1LL << bit); // must set this bit
}
}
cout << answer << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |