#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 6;
int n, a, b;
int y[N], p[N];
void solveTestCase() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> y[i];
p[0] = y[0];
for (int i = 1; i < n; i++)
p[i] = y[i] + p[i - 1];
int ans = 0;
for (int i = 5; i >= 0; i--) {
int dp[n];
fill(dp, dp + n, 1e14);
int up = ans + (1ll << i);
bool check = y[0] < up;
dp[0] = 1;
for (int j = 1; j < n; j++) {
check = check && y[j] < up;
if (p[j] < up && (p[j] | up) < up + (1ll << i) && (p[j] & (1 << i)) == 0)
dp[j] = 1;
for (int k = j - 1; k >= 0; k--) {
if ((p[j] - p[k + 1] + y[k + 1]) < up && ((p[j] - p[k + 1] + y[k + 1]) | up) < up + (1ll << i) && ((p[j] - p[k + 1] + y[k + 1]) & (1 << i)) == 0)
dp[j] = min(dp[j], dp[k] + 1);
}
}
if (!check || dp[n - 1] > b)
ans = up;
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
//cin >> test;
while (test--)
solveTestCase();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
436 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |