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<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<queue>
using namespace std;
int t[3000];
long long sumy[3000];
int dp[3000];
bool dp2[3000][3000];
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,a,b;
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>t[i];
sumy[i]=sumy[i-1]+t[i];
}
if(a==1)
{
long long wynik=0;
long long szukam=0;
for(int c=60;c>=0;c--)
{
for(int i=1;i<=n;i++)
dp[i]=1e9;
szukam=wynik+((long long)1<<c)-1;
long long mam=0;
for(int i=1;i<=n;i++)
{
mam=0;
for(int j=i-1;j>=0;j--)
{
mam+=t[j+1];
long long teraz=szukam|mam;
if(teraz!=szukam)
continue;
dp[i]=min(dp[i],dp[j]+1);
}
}
if(dp[n]>b)
wynik+=((long long)1<<c);
}
cout<<wynik;
}
else{
long long wynik=0,szukam=0,mam=0;
for(int c=60;c>=0;c--)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dp2[i][j]=0;
szukam=wynik+((long long)1<<c)-1;
dp2[0][0]=1;
for(int i=1;i<=n;i++)
{
mam=0;
for(int j=i-1;j>=0;j--)
{
mam+=t[j+1];
long long teraz=szukam|mam;
if(teraz!=szukam)
continue;
for(int k=0;k<=n;k++)
{
if(dp2[j][k])
dp2[i][k+1]=1;
}
}
}
bool ok=0;
for(int i=a;i<=b;i++)
if(dp2[n][i]==1)
ok=1;
if(ok==0)
wynik+=((long long)1<<c);
}
cout<<wynik;
}
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... |