# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387446 | mehrdad_sohrabi | Towns (IOI15_towns) | C++14 | 0 ms | 0 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.
/// Black lives matter
#include <bits/stdc++.h>
//#include "towns.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=200;
/*
ll disin[N][N];
int getDistance(ll u,ll v){
return disin[u][v];
}
*/
ll dis[N][N];
ll t[3];
int32_t hubDistance(int32_t n, int32_t sub) {
memset(t,0,sizeof t);
ll mx0=0,id0=0,mx1=0,id1=0;
memset(dis,-1,sizeof dis);
for (int i=1;i<n;i++){
if (dis[0][i]==-1) dis[0][i]=getDistance(0,i),dis[i][0]=dis[0][i];
if (dis[0][i]>mx0){
mx0=dis[0][i];
id0=i;
}
}
for (int i=0;i<n;i++){
if (dis[id0][i]==-1) dis[id0][i]=getDistance(id0,i),dis[i][id0]=dis[id0][i];
if (dis[id0][i]>mx1){
mx1=dis[id0][i];
id1=i;
}
}
ll ans=dis[id0][id1],mn=1e9,rast=0;
t[0]++;
t[2]++;
for (int i=0;i<n;i++){
if (i==id0 || i==id1) continue;
dis[id1][i]=getDistance(id1,i);
dis[i][id1]=dis[id1][i];
ll dd=dis[id0][i]-dis[id1][i];
ll z=abs(dis[id0][i]-dis[id1][i]);
mn=min(mn,z);
if (mn==z) rast=dd;
}
for (int i=0;i<n;i++){
if (i==id0 || i==id1) continue;
ll dd=dis[id0][i]-dis[id1][i];
if (dd==rast) t[1]++;
if (dd<rast) t[0]++;
if (dd>rast) t[2]++;
}
ll zz=1;
if (t[0]>n/2 || t[1]>n/2 || t[2]>n/2) zz=-1;
return zz*(ans+mn)/2;
}
/*
int32_t main(){
ll x,y;
cin >> x >> y;
ll n;
cin >> n;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++) cin >> disin[i][j];
}
cout << hubDistance(n,y);
}
*/
/*
1 1
10
0 16 16 16 20 16 20 16 8 16
16 0 16 16 20 8 20 16 16 16
16 16 0 8 20 16 20 16 16 16
16 16 8 0 20 16 20 16 16 16
20 20 20 20 0 20 22 20 20 20
16 8 16 16 20 0 20 16 16 16
20 20 20 20 22 20 0 20 20 20
16 16 16 16 20 16 20 0 16 8
8 16 16 16 20 16 20 16 0 16
16 16 16 16 20 16 20 8 16 0
*/