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;
const int DIM = 2005;
int dp1[DIM]; long long psm[DIM];
bool dp2[DIM][DIM];
bool solve(long long val, int n, int a, int b) {
long long aux = ((1LL << 50) - 1) ^ val;
if (a == 1) {
dp1[0] = 0;
for (int i = 1; i <= n; ++i) {
dp1[i] = b + 1;
for (int j = i; j >= 1; --j) {
if (!((psm[i] - psm[j - 1]) & aux)) {
dp1[i] = min(dp1[i], dp1[j - 1] + 1); } } }
return dp1[n] <= b; }
else {
dp2[0][0] = true;
for (int k = 1; k <= b; ++k) {
for (int i = 1; i <= n; ++i) {
dp2[k][i] = false;
for (int j = i; j >= 1; --j) {
if (!((psm[i] - psm[j - 1]) & aux)) {
dp2[k][i] |= dp2[k - 1][j - 1]; } } } }
for (int k = a; k <= b; ++k) {
if (dp2[k][n]) {
return true; } }
return false; } }
int main(void) {
#ifdef HOME
freopen("sculpture.in", "r", stdin);
freopen("sculpture.out", "w", stdout);
#endif
int n, a, b; cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> psm[i]; psm[i] += psm[i - 1]; }
long long ans = 0;
for (long long i = (1LL << 49); i; i >>= 1) {
if (!solve(ans ^ (i - 1), n, a, b)) {
ans ^= i; } }
cout << ans;
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... |