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;
const int N=2007;
ll partsum[N];
bool dp2[N][N];
int n,A,B,dp[N],bit[60];
bool solve()
{
ll val=0;
for(int i=0;i<44;i++) val+=bit[i]*(1LL<<i);
if(A==1)
{
dp[0]=0;
for(int i=1;i<=n;i++)
{
dp[i]=N;
for(int j=0;j<i;j++)
{
if(((partsum[i]-partsum[j]) | val)== val) dp[i]=min(dp[i],dp[j]+1);
}
}
if(dp[n]<=B) return true;
return false;
}
dp2[0][0]=true;
for(int i=1;i<=n;i++) dp2[i][0]=false;
for(int i=1;i<=B;i++) dp2[0][i]=false;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=B;j++)
{
dp2[i][j]=false;
for(int k=0;k<i;k++)
{
if(dp2[k][j-1] && ((partsum[i]-partsum[k])| val) == val) {
dp2[i][j]=true;
break;
}
}
}
}
for(int i=A;i<=B;i++)
if(dp2[n][i]) return true;
return false;
}
int main()
{
cin>>n>>A>>B;
for(int i=1,x;i<=n;i++) cin>>x, partsum[i]=partsum[i-1]+x;
for(int i=0;i<44;i++) bit[i]=1;
for(int i=43;i>=0;i--)
{
bit[i]=0;
bool ok=solve(); if(!ok) bit[i]=1;
}
ll res=0;
for(int i=0;i<44;i++) res+=bit[i]*(1LL<<i);
cout<<res<<endl;
}
# | 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... |