# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098329 | alexander707070 | Towns (IOI15_towns) | C++14 | 99 ms | 28496 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>
#include "towns.h"
#define MAXN 200
using namespace std;
int n,r,mult;
int dist[MAXN],s,t,diameter,dist2[MAXN],pref[1000007];
vector< pair<int,int> > v[1000007];
int hubDistance(int N, int sub) {
int n=N; mult=1;
for(int i=0;i<=1000000;i++){
v[i].clear(); pref[i]=0;
}
s=0; dist[0]=0;
for(int i=1;i<n;i++){
dist[i]=getDistance(0,i);
if(dist[i]>dist[s])s=i;
}
dist[s]=0; t=s;
for(int i=0;i<n;i++){
if(i==s)continue;
dist[i]=getDistance(s,i);
if(dist[i]>dist[t])t=i;
}
diameter=dist[t]; r=1000000;
for(int i=0;i<n;i++){
if(i==s or i==t)continue;
dist2[i]=getDistance(t,i);
int sum=(diameter+dist[i]+dist2[i])/2;
v[sum-dist2[i]].push_back({i,sum-diameter});
pref[sum-dist2[i]]++;
r=min(r,max(sum-dist[i],sum-dist2[i]));
}
for(int i=1;i<=1000000;i++)pref[i]+=pref[i-1];
for(int i=0;i<n;i++){
if(i==s or i==t)continue;
int sum=(diameter+dist[i]+dist2[i])/2;
if(max(sum-dist[i],sum-dist2[i]) != r)continue;
int a=pref[sum-dist2[i]-1];
int b=v[sum-dist2[i]].size();
int c=n-a-b;
if(a<=n/2 and b<=n/2 and c<=n/2){
mult=-1; break;
}
}
return r*mult;
}
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... |