#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=2000;
const ll mod=1e9+7;
const ll inf=1e18+500;
ll a[maxn];
ll n,A,B;
ll dpa1[maxn];
bool shoda1(ll res){
dpa1[0]=0;
for(ll i=1;i<=n;i++){
dpa1[i]=inf;
ll sum=0;
for(ll j=i;j>=1;j--){
sum+=a[j];
if((sum|res)==res){
dpa1[i]=min(dpa1[i],dpa1[j-1]+1);
}
}
}
if(dpa1[n]<=B){
return 1;
}
return 0;
}
bool dp[maxn][maxn];
bool shod(ll res){
dp[0][0]=1;
for(ll i=1;i<=n;i++){
for(ll z=1;z<=n;z++){
ll sum=0;
for(ll j=i;j>=1;j--){
sum+=a[j];
if((sum|res)==res){
dp[i][z]|=dp[j-1][z-1];
}
}
}
}
for(ll i=A;i<=B;i++){
if(dp[n][i]){
return 1;
}
}
return 0;
}
int main(){
cin>>n>>A>>B;
if(n<=20){
for(ll i=0;i<n;i++){
cin>>a[i];
}
ll ans=inf;
for(ll i=0;i<(1LL<<(n-1));i++){
ll sum=0;
ll orr=0;
for(ll j=0;j<n;j++){
sum+=a[j];
if((i>>j)&1){
orr|=sum;
sum=0;
}
}
orr|=sum;
ans=min(ans,orr);
}
cout<<ans;
return 0;
}
for(ll i=1;i<=n;i++){
cin>>a[i];
}
if(A==1){
ll res=0;
for(ll i=60;i>=0;i--){
if(!shoda1(res+(1LL<<i)-1)){
res+=(1LL<<i);
}
}
cout<<res<<endl;
}
else{
ll res=0;
for(ll i=60;i>=0;i--){
if(!shod(res+(1LL<<i)-1)){
res+=(1LL<<i);
}
}
cout<<res<<endl;
}
}
/*
. _______ __ ___ ________ ________ _________ _________ ________
. / \ | | / / / \ | \ / \ | | | __ \
. / _____/ | | / / / ___ \ | ___ \ | _______/ | ______| | | \ \
. / / | |/ / / / \ \ | | \ \ | (______ | |_____ | |__/ /
. | | | / | / \ | | | | | \ \ | | | __/
. | | | \ | \ / | | | | | \______ \ | ______| | \
. \ \_____ | |\ \ \ \___/ / | |___/ / _______) | | |_____ | |\ \
. \ \ | | \ \ \ / | / / / | | | | \ \
. \_______/ |__| \__\ \________/ |________/ \________/ |________| |___| \__\
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Incorrect |
2 ms |
428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
428 KB |
Output is correct |
2 |
Correct |
2 ms |
428 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Incorrect |
2 ms |
528 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
528 KB |
Output is correct |
2 |
Correct |
2 ms |
528 KB |
Output is correct |
3 |
Correct |
1 ms |
664 KB |
Output is correct |
4 |
Correct |
2 ms |
664 KB |
Output is correct |
5 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
2 |
Correct |
2 ms |
664 KB |
Output is correct |
3 |
Correct |
2 ms |
664 KB |
Output is correct |
4 |
Correct |
2 ms |
664 KB |
Output is correct |
5 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
2 |
Correct |
2 ms |
664 KB |
Output is correct |
3 |
Correct |
2 ms |
664 KB |
Output is correct |
4 |
Correct |
2 ms |
664 KB |
Output is correct |
5 |
Incorrect |
2 ms |
664 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |