#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[2010][2010];
int ar[2010];
int ps[2010];
int A;int B;
int n;
int ok(int msk){
dp[0][0]=1;
for(int k=1;k<=B;k++){
for(int i=1;i<=n;i++){
dp[k][i]=0;
}
vector<int>vc;
if(dp[k-1][0]){vc.push_back(0);}
for(int i=1;i<=n;i++){
for(int j=(int)vc.size()-1;j>=0;j--){
int v=ps[i]-ps[vc[j]];
if( ((v|msk)==msk) ){
dp[k][i]=1;break;
}
}
if(dp[k-1][i]){
vc.push_back(i);
}
}
if(dp[k][n]==1&&k>=A){return 1;}
}
return 0;
}
int dp2[2010];
int ok1(int msk){
for(int i=0;i<=n;i++){
dp2[i]=1e9;
}
dp2[0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
if(dp2[j]&&(((ps[i]-ps[j])|msk)==msk)){
dp2[i]=min(dp2[i],dp2[j]+1);
}
}
}
if(dp2[n]<=B){return 1;}
return 0;
}
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>A>>B;
for(int i=1;i<=n;i++){
cin>>ar[i];
ps[i]=ar[i]+ps[i-1];
}
int msk=(1ll<<46)-1;
for(int bt=45;bt>=0;bt--){
if(A==1){
if(ok1(msk^(1ll<<bt))){
msk^=(1ll<<bt);
}
continue;
}
if(ok(msk^(1ll<<bt))){
msk^=(1ll<<bt);
}
}
cout<<msk;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |