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;
long long dp1[2005][2005], dp2[2005], a[2005], b[2005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, l, r, x, loog=0, cur=0;
cin >> n >> l >> r;
for (long long i=1; i<=n; i++)
cin >> a[i];
for (long long i=1; i<=n; i++)
b[i]=b[i-1]+a[i];
x=b[n];
while (x)
{
x/=2;
loog++;
}
if (l==1)
{
for (long long i=loog-1; i>=0; i--)
{
cur|=1<<i;
dp2[0]=0;
for (long long j=1; j<=n; j++)
dp2[j]=1e18;
for (long long j=1; j<=n; j++)
for (long long k=0; k<j; k++)
if (!(cur&(b[j]-b[k])))
dp2[j]=min(dp2[j], dp2[k]+1);
if (dp2[n]>r)
cur^=1<<i;
}
}
else
{
long long cur=0;
for (long long i=loog-1; i>=0; i--)
{
cur|=1<<i;
dp1[0][0]=1;
for (long long j=1; j<=n; j++)
for (long long k=1; k<=j; k++)
dp1[j][k]=0;
for (long long j=1; j<=n; j++)
{
for (long long k=1; k<=j; k++)
{
for (long long m=k-1; m<j; m++)
if (!(cur&(b[j]-b[m])))
dp1[j][k]=1;
}
}
bool imp=1;
for (long long i=l; i<=r; i++)
{
if (dp1[n][i])
{
imp=0;
break;
}
}
if (imp)
cur^=1<<i;
}
}
cout << pow(2, loog)-cur-1;
return 0;
}
# | 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... |