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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 2100;
ll n, a, b;
ll arr[maxn];
ll dp[maxn];
ll dpmax[maxn];
bool check(ll mask) {
dp[0] = 0LL;
for(int i=1;i<=n;i++) {
ll sum = 0LL;
dpmax[i] = 0LL;
dp[i] = INT_MAX;
for(int lst=i;lst>=1;lst--) {
sum += arr[lst];
if((sum & mask) == sum) {
dp[i] = min(dp[i], dp[lst-1] + 1);
dpmax[i] = max(dpmax[i], dp[lst-1] + 1);
}
}
}
return dp[n] <= b && dpmax[n] >= a;
}
int main() {
cin>>n>>a>>b;
for(int i=1;i<=n;i++) {
cin>>arr[i];
}
ll mask = 0LL;
for(ll bit=50LL;bit>=0;bit--) {
ll temp_mask = mask + ((1LL<<bit) - 1);
//cout<<temp_mask<<": "<<check(temp_mask)<<"\n";
if(!check(temp_mask)) mask += (1LL<<bit);
}
cout<<mask<<"\n";
}
# | 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... |