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;
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, A, B;
cin >> n >> A >> B;
vector<int> x(n + 1);
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
vector<int> dp_min(n + 1), dp_max(n + 1);
long long answer = 0;
for (int bit = 40; bit >= 0; bit--) {
fill(dp_min.begin(), dp_min.end(), n + 1);
fill(dp_max.begin(), dp_max.end(), -(n + 1));
dp_min[0] = dp_max[0] = 0;
for (int i = 1; i <= n; i++) {
long long sum = 0;
for (int j = i - 1; j >= 0; j--) {
sum += x[j + 1];
if (((sum | answer) >> bit) == (answer >> bit)) {
dp_min[i] = min(dp_min[i], dp_min[j] + 1);
dp_max[i] = max(dp_max[i], dp_max[j] + 1);
}
}
}
// cerr << dp_min[n] << " " << dp_max[n] << " " << answer << " " << bit << "\n";
if (std::max(A, dp_min[n]) > std::min(B, dp_max[n])) {
answer += (1LL << bit);
}
}
cout << answer << "\n";
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... |