#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2100;
int n, A, B, y[N], dp[N];
bool can[N][N];
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++)
cin >> y[i];
int ans = 0;
for (int b = 60; b >= 0; b--) {
if (A == 1) {
for (int i = 1; i <= n; i++)
dp[i] = n + 1;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
int sum = y[i];
for (int j = i - 1; j >= 0; j--) {
if (((sum >> b) | (ans >> b)) == (ans >> b))
dp[i] = min(dp[i], dp[j] + 1);
sum += y[j];
}
}
if (dp[n] > B)
ans |= (1ll << b);
} else {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
can[i][j] = false;
can[0][0] = true;
for (int i = 1; i <= n; i++) {
int sum = y[i];
for (int j = i - 1; j >= 0; j--) {
if (((sum >> b) | (ans >> b)) == (ans >> b))
for (int k = 0; k < n; k++)
if (can[j][k])
can[i][k + 1] = true;
sum += y[j];
}
}
bool good = false;
for (int i = A; i <= B && !good; i++)
if (can[n][i]) good = true;
if (!good)
ans |= (1ll << b);
}
}
cout << ans;
}
# | 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... |