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;
#define int long long
int n,a,b;
int y[2005],sump[2005];
bool verif(int lim)
{
vector<vector<bool>> dp(n+2,vector<bool>(n+2,0));
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int cnt=1;cnt<=n;cnt++)
{
dp[i][cnt]=0;
for(int j=i-1;j>=0;j--)
{
int s = sump[i]-sump[j];
if(s>lim) break;
if(dp[j][cnt-1] && (lim|s)==lim)
{
dp[i][cnt]=1;
break;
}
}
}
}
for(int i=a;i<=b;i++)
if(dp[n][i])
return 1;
return 0;
}
/**
dp[i][cnt] = 0/1
dp[i][cnt] |= dp[x][cnt-1], daca
*/
signed main()
{
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>y[i];
sump[i] = sump[i-1]+y[i];
}
if(a==1)
{
int pref=(1<<30)-1;
for(int b=29;b>=0;b--)
{
pref -= (1<<b);
if(!verif(pref))
pref += (1<<b);
}
cout<<pref;
}
else
{
int pref=(1LL<<60)-1;
for(int b=59;b>=0;b--)
{
pref -= (1LL<<b);
if(!verif(pref))
pref += (1LL<<b);
}
cout<<pref;
}
return 0;
}
/**
6 1 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... |