#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, a, b;
cin >> n >> a >> b;
vector<ll> c(n + 1);
for (int i = 1; i <= n; i++) {
cin >> c[i];
c[i] += c[i - 1];
}
ll ans = (1LL << 41) - 1;
auto Solve = [&] () {
vector<vector<bool>> dp(n + 1, vector<bool>(b + 1));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int p = 1; p <= b; p++) {
for (int j = 0; j < i; j++) {
ll o = c[i] - c[j];
if (dp[j][p - 1] && (o | ans) == ans) dp[i][p] = 1;
}
}
}
for (int p = a; p <= b; p++) if (dp[n][p]) return true;
return false;
};
auto Solve1 = [&] () {
vector<int> dp(n + 1, 1e9);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
ll o = c[i] - c[j];
if ((o | ans) == ans) smin(dp[i], dp[j] + 1);
}
}
cout << ans << sp << dp[n] << en;
return dp[n] <= b;
};
for (int i = 40; i >= 0; i--) {
ll x = 1LL << i;
ans -= x;
if (a == 1) {if (!Solve1()) ans += x;}
else {if (!Solve()) ans += x;}
}
cout << ans << en;
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |