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 <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define int long long
int dp[2001];
int dp2[101][101];
int psum[2001];
signed main()
{
int N,a,b;
cin >> N >> a >> b;
int i;
for(i=0;i<N;i++)
{
int v;
cin >> v;
psum[i+1]=psum[i]+v;
}
if(a==1)
{
int cu=(1LL<<42)-1;
for(i=41;i>=0;i--)
{
cu-=1LL<<i;
int j;
memset(dp,1,sizeof(dp));
dp[0]=0;
for(j=1;j<=N;j++)
{
int k;
for(k=0;k<j;k++)
{
if(((psum[j]-psum[k])|cu)==cu)
{
dp[j]=min(dp[j],dp[k]+1);
}
}
}
if(dp[N]>b)
cu+=1LL<<i;
}
cout <<cu;
}
else
{
int cu=(1LL<<42)-1;
for(i=41;i>=0;i--)
{
cu-=1LL<<i;
int j;
memset(dp2,0,sizeof(dp2));
dp2[0][0]=1;
for(j=1;j<=N;j++)
{
int k;
for(k=0;k<j;k++)
{
if(((psum[j]-psum[k])|cu)==cu)
{
int l;
for(l=0;l<N;l++)
{
dp2[j][l+1]|=dp2[k][l];
}
}
}
}
int po=0;
for(j=a;j<=b;j++)
{
po|=dp2[N][j];
}
if(!po)
cu+=1LL<<i;
}
cout <<cu;
}
}
# | 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... |