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<cstring>
#define endl '\n'
using namespace std;
long long n,a,b,m[2005],r=0,pref[2005],ts;
bool dp[2005][2005];
bool isposs(long long num)
{
for(int i=0;i<=2000;i++)
memset(dp[i],0,sizeof(dp[i]));
dp[0][0]=1;
bool is=0;
for(int i=1;i<=n;i++)
{
for(long long j=i;j>=1;j--)
{
ts=pref[i]-pref[j-1];
is=0;
for(int bit=35;bit>=0;bit--)
{
if(((1<<bit)&num)==0 && ((1<<bit)&ts)==1)
{
is=1;break;
}
}
if(is) continue;
for(int brg=1;brg<=min(j,b);brg++)
{
dp[i][brg]|=dp[j-1][brg-1];
}
}
}
bool re=0;
for(int i=a;i<=b;i++)
{
re|=dp[n][i];
}
return re;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>m[i];
pref[i]=pref[i-1]+m[i];
}
r=(1<<36)-1;
for(int i=35;i>=0;i--)
{
if(isposs((1<<i)^r))
{
r^=(1<<i);
}
}
cout<<r<<endl;
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message (stderr)
sculpture.cpp: In function 'int main()':
sculpture.cpp:56:9: warning: left shift count >= width of type [-Wshift-count-overflow]
56 | r=(1<<36)-1;
| ~^~~~
# | 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... |