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 ll;
#define endl '\n'
bool dp[105][105];
int dp2[105];
void solve(){
int n,l,r;
cin>>n>>l>>r;
vector<ll> v(n);
for(auto &i:v) cin>>i;
vector<ll> prefix = v;
for(int i=1;i<n;i++) prefix[i] += prefix[i-1];
auto getSum = [&](int i,int j){
return prefix[j] - (i ? prefix[i-1] : 0);
};
if(n <= 100){
ll cur = 0;
dp[n][0] = 1;
for(int bt=41;bt>=0;bt--){
for(int i=n-1;i>=0;i--){
for(int j=0;j<=n;j++){
dp[i][j] = 0;
if(j){
for(int k=i;k<n;k++){
if(((getSum(i,k) | cur) >> bt) == (cur>>bt)){
dp[i][j] |= dp[k+1][j-1];
}
}
}
}
}
for(int i=l;i<=r;i++){
if(dp[0][i]) goto gt;
}
cur |= (1LL<<(ll)bt);
gt:continue;
}
cout<<cur<<endl;
}
else {
ll cur = 0;
for(int bt=41;bt>=0;bt--){
for(int i=n-1;i>=0;i--){
for(int j=0;j<=n;j++){
dp2[i] = 1e9;
if(j){
for(int k=i;k<n;k++){
if(((getSum(i,k) | cur) >> bt) == (cur>>bt)){
dp2[i] = min(dp2[i],dp2[k+1] + 1);
}
}
}
}
}
if(dp2[0] > r) cur |= (1LL<<(ll)bt);
}
cout<<cur<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
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... |