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 int64;
const int maxn = 2e3 + 2;
int64 pref [maxn];
int64 arr[maxn];
int n,a,b;
bool check (int64 rs) {
int mn[maxn] = {}, mx[maxn] = {};
for (int i = 1; i <= n; i++){
mn[i] = 1e9, mx[i] = -1e9;
for (int j = 0; j < i; j++){
if (((pref[i] - pref[j]) & rs) == (pref[i] - pref[j])) {
mn[i] = min(mn[i], mn[j] + 1);
mx[i] = max(mx[i], mx[j] + 1);
}
}
}
return mn[n] <= b && mx[n] >= a;
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++){
cin >> arr[i];
pref[i] = pref[i-1] + arr[i];
}
int64 rs = (1ll << 41) - 1;
for (int64 i = 40; i >= 0; i--){
if (check(rs ^ (1ll << i))) rs^=(1ll << i);
}
cout << rs << "\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... |