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 int
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define sz size()
const int N = 2e5 + 1;
using namespace std;
int a, b, n, arr[N], dp[N];
bool check(ll x){
for(int i = 1; i <= n; i++) dp[i] = 1e9;
for(int i = 1; i <= n; i++){
ll sum = 0;
for(int j = i; j > 0; j--){
sum += arr[j];
if((sum & x) == sum){
dp[i] = min(dp[i], dp[j-1] + 1);
}
}
}
return dp[n] <= b;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
cin >> arr[i];
}
ll x = (1LL<<42)-1;
for(int i = 41; i >= 0; i--){
x -= (1LL<<i);
if(!check(x)) x += (1LL<<i);
}
cout << x << '\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... |