#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, A, B;
cin >> n >> A >> B;
vector<int> x(n + 1);
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
long long answer = 0;
if (n <= 100) {
for (int bit = 40; bit >= 0; bit--) {
vector<vector<bool>> dp(B + 1, vector<bool>(n + 1));
dp[0][0] = true;
for (int i = 1; i <= B; i++) {
for (int j = 1; j <= n; j++) {
long long sum = 0;
for (int k = j - 1; k >= 0; k--) {
sum += x[k + 1];
if ((sum >> bit) == (answer >> bit)) {
dp[i][j] = (dp[i][j] | dp[i - 1][k]);
}
}
}
}
bool good = false;
for (int i = A; i <= B; i++) {
good |= dp[i][n];
}
if (!good) {
answer += (1LL << bit);
}
}
} else {
for (int bit = 40; bit >= 0; bit--) {
vector<bool> dp(n + 1);
dp[0] = true;
for (int j = 1; j <= n; j++) {
long long sum = 0;
for (int k = j - 1; k >= 0; k--) {
sum += x[k + 1];
if ((sum >> bit) == (answer >> bit)) {
dp[j] = (dp[j] | dp[k]);
}
}
}
if (dp[n] == false) {
answer += (1LL << bit);
}
}
}
cout << answer;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |