# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095476 | MMihalev | Towns (IOI15_towns) | C++14 | 12 ms | 1224 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 "towns.h"
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAX_N=2e2+2;
int diam;
int tov[MAX_N];
int tou[MAX_N];
int to0[MAX_N];
int n;
int hubDistance(int N, int sub)
{
n=N;
int u=0;
int far=0,v;
for(int i=1;i<n;i++)
{
int cur=getDistance(u,i);
to0[i]=cur;
if(cur>far)
{
far=cur;
v=i;
}
}//0->v
diam=0;
for(int i=0;i<n;i++)
{
if(i==v)continue;
int cur;
if(i==0)cur=to0[v];
else cur=getDistance(i,v);
tov[i]=cur;
if(cur>diam)
{
diam=cur;
u=i;
}
}//v->u
for(int i=0;i<n;i++)
{
if(i==u)continue;
if(i==0)tou[i]=to0[u];
if(i==v)tou[i]=tov[u];
tou[i]=getDistance(u,i);
}//u->all
int cntneg=0,cntpos=0;
int mindif=1e9;
for(int i=0;i<n;i++)
{
if(i==u or i==v)continue;
int x=tou[i];
int y=tov[i];
int com=((x+y)-diam)/2;
x-=com;
y-=com;
int res=x-y;
if(res<0)cntneg++;
else if(res>0)cntpos++;
mindif=min(mindif,abs(res));
}
int R=(diam-mindif)/2+mindif;
return R;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |