#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const int N=1e3+1;
const int M=1e6+1;
const ll inf=1e9+11;
const ld EPS=1e-6;
const int INF=1e9;
const ll mod=/*999999001*/1e9+7;
const int dx[4]={1,0,0,-1};
const int dy[4]={0,1,-1,0};
ll a[N];
ll dp[N][N];
void compute(int i,int l,int r,int optl,int optr){
if(l>r)return ;
int mid=(l+r)/2;
int opt=-1;
dp[i][mid]=INF;
for(int k=max(i,optl);k<=min(mid,optr);k++){
if((dp[i-1][k-1]|(a[mid]-a[k-1]))<dp[i][mid]){
dp[i][mid]=(dp[i-1][k-1]|(a[mid]-a[k-1]));
opt=k;
}
}
compute(i,l,mid-1,optl,opt);
compute(i,mid+1,r,opt,optr);
}
void solve(){
int n;
cin>>n;
int l,r;
cin>>l>>r;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=1;i<=n;i++){
dp[1][i]=a[i];
}
ll ans=INF;
if(l==1)ans=min(ans,dp[1][n]);
for(int i=2;i<=r;i++){
compute(i,1,n,1,n);
if(i>=l)ans=min(ans,dp[i][n]);
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
solve();
cout<<nl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |