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>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e3+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,a,b,u[N],v[N][N];
bool oka(ll k){
memset(v,0,sizeof(v));
v[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=b&&j<=i;j++){
v[i][j]=0;
for(int g=1;g<=i;g++){
//cout<<i-g<<"\n";
if(((u[i]-u[i-g])|k)<=k&&v[i-g][j-1]==1)v[i][j]=1;
}
}
}
for(int i=a;i<=b;i++)if(v[n][i])return 1;
return 0;
}
bool okb(ll k){
ll f[N];
f[0]=0;
for(int i=1;i<=n;i++){
f[i]=INF;
for(int j=1;j<=i;j++){
if(((u[i]-u[i-j])|k)<=k)f[i]=min(f[i],f[i-j]+1);
}
}
return (f[n]<=b);
}
void solvea(){
ll bit=(1LL<<41)-1;
for(int i=40;i>=0;i--){
if(oka(bit^(1LL<<i)))bit^=(1LL<<i);
}
cout<<bit<<"\n";
}
void solveb(){
ll bit=(1LL<<41)-1;
for(int i=40;i>=0;i--){
if(okb(bit^(1LL<<i)))bit^=(1LL<<i);
}
cout<<bit<<"\n";
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>a>>b;
REP1(i,n)cin>>u[i],u[i]+=u[i-1];
if(a==1){
solveb();
}else{
solvea();
}
return 0;
}
/*
6 2 3
8 1 2 1 5 4
*/
# | 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... |