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 <algorithm>
using namespace std;
long long N, A, B, X[2009], dp[2009][2009], res[2009], bit[50];
bool solve() {
if (A == 1) {
long long P = 0; for (int i = 0; i < 50; i++) P += bit[i] * (1LL << i);
for (int i = 0; i <= N + 1; i++) res[i] = (1 << 30);
res[1] = 0;
for (int i = 1; i <= N; i++) {
long long s = 0;
for (int j = i + 1; j <= N + 1; j++) {
s += X[j - 1];
if ((s | P) == P) res[j] = min(res[j], res[i] + 1);
}
}
if (res[N + 1] <= B) return true;
return false;
}
else {
long long P = 0; for (int i = 0; i < 50; i++) P += bit[i] * (1LL << i);
for (int i = 0; i <= N + 1; i++) { for (int j = 0; j <= B; j++) dp[i][j] = 0; }
dp[1][0] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= B; j++) {
if (dp[i][j] == 0) continue;
long long s = 0;
for (int k = i + 1; k <= N + 1; k++) {
s += X[k - 1];
if ((s | P) == P) { dp[k][j + 1] = 1; }
}
}
}
for (int i = A; i <= B; i++) { if (dp[N + 1][i] == 1) return true; }
return false;
}
}
int main() {
cin >> N >> A >> B;
for (int i = 1; i <= N; i++) cin >> X[i];
for (int i = 0; i < 50; i++) bit[i] = 1;
for (int i = 49; i >= 0; i--) {
bit[i] = 0;
bool OK = solve(); if (OK == false) bit[i] = 1;
}
long long ret = 0;
for (int i = 0; i < 50; i++) ret += bit[i] * (1LL << i);
cout << ret << 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... |