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 "towns.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int nmax=205;
int n;
int d[2][nmax];
int to[nmax],wh[nmax],sz[nmax];
vector<int> domin[nmax];
vector<int> cand;
int eq(int x,int y)
{
return (to[x]+to[y]!=getDistance(x,y));
}
bool checkHub(int x)
{
for(int i=0;i<n;i++)
if(wh[i]==x)
cand.push_back(i);
int act=0,bal=0;
for(auto it: cand)
{
if(bal==0)
{
act=it;
bal++;
}
else
{
if(eq(act,it)) bal++;
else
{
domin[act].push_back(it);
bal--;
}
}
sz[act]++;
}
int ap=0;
for(auto it:cand)
{
if(sz[it])
{
if(eq(act,it)) ap+=sz[it]-(int)domin[it].size();
else
{
for(auto oth: domin[it])
{
ap+=eq(act,oth);
}
}
}
}
return (ap<=n/2);
}
int hubDistance(int N, int sub) {
int d1=0,R=0,mx=0;
n=N;
for(int i=1; i<n; i++)
{
d[0][i]=getDistance(0,i);
if(d[0][i]>d[0][d1])
d1=i;
}
for(int i=0; i<n; i++)
if(i!=d1)
{
d[1][i]=getDistance(d1,i);
if(d[1][i]>mx)
mx=d[1][i];
}
int minDist=(1<<30);
for(int i=0; i<n; i++)
{
to[i]=(d[0][i]+d[1][i]-d[0][d1])/2;
wh[i]=(d[1][i]-to[i]);
if(max(wh[i],mx-wh[i])<minDist)
minDist=max(wh[i],mx-wh[i]);
}
/*vector<int> hubs;
for(int i=0;i<n;i++)
if(max(wh[i],mx-wh[i])==minDist)
hubs.push_back(wh[i]);
sort(hubs.begin(),hubs.end());
hubs.resize(unique(hubs.begin(),hubs.end())-hubs.begin());
bool ok=0;
for(auto cen :hubs)
{
int mici=0,mari=0;
for(int i=0;i<n;i++)
{
if(wh[i]<cen) mici++;
if(wh[i]>cen) mari++;
}
if(mici<=n/2&&mari<=n/2)
ok=checkHub(cen);
}*/
R=minDist;
// if(!ok) R=-R;
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:60:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int N, int sub) {
^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |