#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int inf = 1e9;
const int lg = 41;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, l, r; cin>>n>>l>>r;
vector<int> a(n + 1);
vector<ll> p(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i];
p[i] = p[i - 1] + a[i];
}
if (l != 1){
ll out = (1LL << (lg + 1)) - 1;
for (int b = lg; b >= 0; b--){
out -= (1LL << b);
vector<vector<bool>> dp(n + 1, vector<bool>(r + 1)); dp[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= i; j++){
ll s = p[i] - p[j - 1];
bool ind = 1;
for (int bb = b; bb <= lg; bb++){
if (((s >> bb) & 1) > ((out >> bb) & 1)){
ind = 0;
break;
}
}
if (ind){
for (int x = 1; x <= r; x++){
dp[i][x] = max(dp[i][x], dp[j - 1][x - 1]);
}
}
}
}
bool ind = 0;
for (int i = l; i <= r; i++){
if (dp[n][i]){
ind = 1;
break;
}
}
if (!ind){
out += (1LL << b);
}
}
cout<<out<<"\n";
return 0;
}
ll out = (1LL << (lg + 1)) - 1;
for (int b = lg; b >= 0; b--){
out -= (1LL << b);
vector<int> dp(n + 1, inf); dp[0] = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= i; j++){
ll s = p[i] - p[j - 1];
bool ind = 1;
for (int bb = b; bb <= lg; bb++){
if (((s >> bb) & 1) > ((out >> bb) & 1)){
ind = 0;
break;
}
}
if (ind){
dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
}
if (dp[n] > r){
out += (1LL << b);
}
}
cout<<out<<"\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... |