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 <iostream>
#include <string.h>
#define int long long
using namespace std;
const int MAX_N = 2000;
int a[MAX_N + 1], subtask5[MAX_N + 1];
bool sepoate[MAX_N + 1][MAX_N + 1];
int n, xmin, xmax;
bool check(int mask, int pos) {
memset(sepoate[0], false, sizeof(sepoate[0]));
sepoate[0][0] = true;
for (int i = 1; i <= n; i++) {
sepoate[i][0] = false;
for (int x = 1; x <= xmax; x++) {
sepoate[i][x] = false;
int sum = 0;
for (int j = i; j >= 1; j--) {
sum += a[j];
if ((sum & ~mask) >= (1LL << pos)) {
continue;
}
if (sepoate[j - 1][x - 1] == true) {
sepoate[i][x] = true;
break;
}
}
}
}
bool ok = false;
for (int i = xmin; i <= xmax; i++) {
ok |= sepoate[n][i];
}
return ok;
}
bool checksubtask5(int mask, int pos = 0) {
subtask5[0] = 0;
for (int i = 1; i <= n; i++) {
subtask5[i] = (1 << 30);
int sum = 0;
for (int j = i; j >= 1; j--) {
sum += a[j];
if ((sum & ~mask) >= (1LL << pos)) {
continue;
}
subtask5[i] = min(subtask5[i], subtask5[j - 1] + 1);
}
}
return subtask5[n] <= xmax;
}
signed main() {
cin >> n >> xmin >> xmax;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (xmin == 1) {
int answer = 0;
for (int bit = 50; bit >= 0; bit--) {
if (checksubtask5(answer, bit) == false) {
answer |= (1LL << bit);
}
}
cout << answer;
} else {
int answer = 0;
for (int bit = 50; bit >= 0; bit--) {
if (check(answer, bit) == false) {
answer |= (1LL << bit);
}
}
cout << answer;
}
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... |