#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int ar = 2e3 + 5;
int n, a[ar], P, Q;
ll dp[ar][ar], suf[ar][ar], sum[ar];
ll get(int l, int r) {
return sum[r] - sum[l - 1];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> P >> Q;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
memset(dp, 0x3f, sizeof(dp));
memset(suf, 0x3f, sizeof(suf));
for(int i = 1; i <= n; ++i) {
dp[i][0] = sum[i];
for(int j = 1; j < i; ++j) {
for(int k = 1; k < i; ++k) {
dp[i][j] = min(dp[i][j], dp[k][j - 1] | get(k + 1, i));
}
}
}
for(int i = n; i >= 1; --i) {
suf[i][0] = get(i, n);
for(int j = 1; j < (n - i + 1); ++j) {
for(int k = n; k > i; --k) {
suf[i][j] = min(suf[i][j], suf[k][j - 1] | get(j, k - 1));
}
}
}
ll ans = 1e18;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= Q - 1; ++j) {
for(int k = 0; k <= Q - 1; ++k) {
if(j + k >= P - 1 && j + k <= Q - 1) ans = min(ans, dp[i][j] | suf[i + 1][k]);
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
63324 KB |
Output is correct |
2 |
Incorrect |
8 ms |
63240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
63320 KB |
Output is correct |
2 |
Incorrect |
8 ms |
63324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
63324 KB |
Output is correct |
2 |
Incorrect |
7 ms |
63324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
63324 KB |
Output is correct |
2 |
Incorrect |
8 ms |
63324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
63320 KB |
Output is correct |
2 |
Incorrect |
8 ms |
63324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |