# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861664 | AndreiBOTO | Bali Sculptures (APIO15_sculpture) | C++14 | 66 ms | 2796 KiB |
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>
#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
///#include <tryhardmode>
///#include <GODMODE::ON>
using namespace std;
#define int long long
const int NMAX=2e3+5;
const int MASK=50;
bool dp1[NMAX][NMAX];
int dp2[NMAX];
int v[NMAX];
int n,a,b;
bool valid_dp1(long long mask,int bit)
{
int i,j,k;
long long s=0;
for(i=1;i<=n;i++)
for(j=0;j<=b;j++)
dp1[i][j]=false;
dp1[0][0]=true;
for(i=0;i<n;i++)
{
for(j=0;j<=b;j++)
{
s=0;
for(k=i+1;k<=n;k++)
{
s+=v[k];
if((((mask>>bit) & (s>>bit))^ (s>>bit))==0)
dp1[k][j+1]|=dp1[i][j];
}
}
}
for(i=a;i<=b;i++)
if(dp1[n][i]==true)
return true;
return false;
}
long long get_ans1()
{
long long mask=0;
int i;
for(i=49;i>=0;i--)
{
if(valid_dp1(mask,i)==false)
mask=mask^(1LL<<i);
}
return mask;
}
void solve1()
{
cout<<get_ans1();
}
bool valid_dp2(long long mask,int bit)
{
int i,j,k;
long long s=0;
for(i=1;i<=n;i++)
dp2[i]=b+1;
dp2[0]=0;
for(i=0;i<n;i++)
{
s=0;
for(k=i+1;k<=n;k++)
{
s+=v[k];
if((((mask>>bit) & (s>>bit))^ (s>>bit))==0)
dp2[k]=min(dp2[k],dp2[i]+1);
}
}
if(dp2[n]<=b)
return true;
return false;
}
long long get_ans2()
{
long long mask=0;
int i;
for(i=49;i>=0;i--)
{
if(valid_dp2(mask,i)==false)
mask=mask^(1LL<<i);
}
return mask;
}
void solve2()
{
cout<<get_ans2();
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
cin>>v[i];
if(a!=1)
solve1();
else
solve2();
return 0;
}
Compilation message (stderr)
# | 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... |