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;
const int64_t MAX=41;
int64_t n,A,B,a[2005];
bool Free[2005][2005],F[2005][2005];
bool f(int64_t i,int64_t j,int64_t mask)
{
if(Free[i][j]==true)
return F[i][j];
Free[i][j]=true;
if(j>B)
return F[i][j]=false;
if(i>n)
return F[i][j]=(A<=j);
for(int64_t t=i;t<=n;t++)
{
int64_t tmp=a[t]-a[i-1];
if((mask|tmp)==mask&&f(t+1,j+1,mask)==true)
return F[i][j]=true;
}
return F[i][j]=false;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n>>A>>B;
for(int64_t i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
int64_t res=(int64_t(1)<<MAX)-1;
for(int64_t i=MAX-1;i>=0;i--)
{
for(int64_t j=1;j<=n;j++)
for(int64_t t=0;t<=B;t++)
Free[j][t]=false;
if(f(1,0,res-(int64_t(1)<<i))==true)
res-=int64_t(1)<<i;
}
cout<<res;
}
# | 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... |