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;
typedef long long ll;
#define int ll
#define pb push_back
const int INF = 1e18;
void run() {
int n, a, b;
cin >> n >> a >> b;
vector<int> y(n);
for (auto &x : y)
cin >> x;
vector<int> pref(1, 0);
for (auto x : y)
pref.pb(pref.back() + x);
if (a == 1) {
int ans = (1ll << 61) - 1;
for (int B = 60; B >= 0; --B) {
ans ^= (1ll << B);
vector<int> dp(n + 1, INF);
dp[0] = 0;
// for (int i = 0; i <= n; ++i) {
// dp[0][i] = 1;
// }
for (int i = 1; i <= n; ++i) {
for (int k = 0; k < i; ++k) {
int sum = pref[i] - pref[k];
if (~ans & sum) {
continue;
}
dp[i] = min(dp[i], dp[k] + 1);
}
}
bool can = (dp[n] <= b);
if (!can) {
ans ^= (1ll << B);
}
}
cout << ans << '\n';
} else {
int ans = (1ll << 61) - 1;
for (int B = 60; B >= 0; --B) {
ans ^= (1ll << B);
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
dp[0][0] = 1;
// for (int i = 0; i <= n; ++i) {
// dp[0][i] = 1;
// }
for (int j = 1; j <= n; ++j) {
for (int i = 1; i <= n; ++i) {
for (int k = 0; k < i; ++k) {
if (!dp[j - 1][k])
continue;
int sum = pref[i] - pref[k];
if (~ans & sum) {
continue;
}
dp[j][i] = 1;
break;
}
}
}
bool can = 0;
for (int i = a; i <= b; ++i) {
if (dp[i][n])
can = 1;
}
if (!can) {
ans ^= (1ll << B);
}
}
cout << ans << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
}
# | 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... |