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 "mountains.h"
using namespace std;
int C[2010][2010];
vector<int>adj[2010];
int DDDP[1<<20];
int maximum_deevs(vector<int> y) {
int n=y.size();
for(int i=1;i<n;i++){
int uuu=i-1;
C[i][i-1]=C[i-1][i]=1;
for(int j=i-1;j--;) {
long long ht=y[j]-y[i],dt=i-j;
long long hb=y[uuu]-y[i],db=i-uuu;
if(ht*db>=hb*dt)
C[i][j]=C[j][i]=1,uuu=j;
}
}
int ans=0;
int sz1=n/2,sz2=n-sz1;
for(int i=0;i<1<<sz2;i++){
vector<int>v;
for(int j=0;j<sz2;j++) if(i&1<<j)
v.push_back(sz1+j),DDDP[i]=max(DDDP[i],DDDP[i^1<<j]);
int bad=0;
for(auto A:v)
for(auto B:v)
if(C[A][B])
bad=1;
if(!bad)DDDP[i]=v.size();
}
for(int i=0;i<1<<sz1;i++){
int K2=1<<sz2;
int todo=0,bad=0;
K2--;
vector<int>v;
for(int j=0;j<sz1;j++)
if(i&1<<j)
v.push_back(j);
for(auto A:v)
for(auto B:v)
if(C[A][B])
bad=1;
if(!bad){
for(auto A:v)
for(int i=sz1;i<n;i++)
if(C[A][i])
todo|=1<<i-sz1;
ans=max(ans,DDDP[K2^todo]+(int)v.size());
}
}
return ans;
}
Compilation message (stderr)
mountains.cpp: In function 'int maximum_deevs(std::vector<int>)':
mountains.cpp:47:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
47 | todo|=1<<i-sz1;
| ~^~~~
# | 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... |