This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, a, b;
cin >> n >> a >> b;
vector<ll> y(n);
for (int i = 0; i < n; ++i) {
cin >> y[i];
}
vector<ll> pref(n + 1, 0);
partial_sum(y.begin(), y.end(), pref.begin() + 1);
ll ans = 0;
if (a == 1) {
for (int bit = 40; bit >= 0; --bit) {
int dp[n + 1];
dp[0] = 0;
fill(dp + 1, dp + n + 1, INT_MAX);
ll b1 = ans >> bit;
for (int i = 0; i <= n; ++i) {
if (dp[i] == INT_MAX) continue;
for (int j = i + 1; j <= n; ++j) {
ll b2 = (pref[j] - pref[i]) >> bit;
if ((b1 | b2) != b1) continue;
dp[j] = min(dp[j], dp[i] + 1);
}
}
if (dp[n] > b) ans |= 1LL << bit;
}
} else {
for (int bit = 40; bit >= 0; --bit) {
bool dp[b + 1][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = true;
ll b1 = ans >> bit;
bool p = false;
for (int i = 0; i < b; ++i) {
for (int j = 0; j <= n; ++j) {
if (!dp[i][j]) continue;
for (int k = j + 1; k <= n; ++k) {
ll b2 = (pref[k] - pref[j]) >> bit;
dp[i + 1][k] |= (b1 | b2) == b1;
}
}
if (i + 1 >= a && dp[i + 1][n]) p = true;
}
if (!p) ans |= 1LL << bit;
}
}
cout << ans << endl;
return 0;
}
# | 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... |