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 <bits/stdc++.h>
using namespace std;
const int N = 117;
int f[N][N];
int d[N][N];
int dis(int x,int y){
if(x==y)return 0;
if(x>y)swap(x,y);
if(f[x][y]==false){
f[x][y]=true;
d[x][y]=getDistance(x,y);
}
return d[x][y];
}
int hubDistance(int N, int sub) {
int x=-1;
for(int i=1;i<N;++i){
if(x==-1||dis(0,x)<dis(0,i)){
x=i;
}
}
int y=-1;
for(int i=0;i<N;++i){
if(y==x)continue;
if(i==x)continue;
if(y==-1||dis(x,y)<dis(x,i)){
y=i;
}
}
map<int,int> mp;
map<int,vector<int>> qan;
for(int i=0;i<N;++i){
if(i==x||i==y){
continue;
}
int d1=dis(x,i);
int d2=dis(y,i);
int l=dis(x,y);
int e=d1+d2-l;
e/=2;
int v=d2-e;
mp[v]=max(mp[v],e);
mp[v]=max(mp[v],d1-e);
mp[v]=max(mp[v],d2-e);
qan[v].push_back(i);
}
int ans=1e9;
int hwx=1;
bool ok=0;
int hx=N/2;
int hwl=1;
int b=0;
for(auto it=mp.begin();it!=mp.end();++it){
ans=min(ans,it->second);
int ds=it->first;
int oth=qan[ds].size();
int r=N-hwl-oth;
if(r>hx||hwl>hx){
}
else if(oth>hx){
b=hx;
if(qan[ds].size()>hx){
for(int j=1;b>0;j++,b--){
if(j>=qan[ds].size())ok=true;
int len=dis(qan[ds][j],qan[ds][0]);
len=dis(qan[ds][j],y)-len;
len/=2;
if(len!=ds){
oth--;
}
}
if(oth>hx)ok=true;
}
else{
ok=true;
}
}
}
return ans*(ok==false ? 1:-1);
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:16:31: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int hubDistance(int N, int sub) {
^
towns.cpp:4:11: note: shadowed declaration is here
const int N = 117;
^
towns.cpp:57:29: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
int oth=qan[ds].size();
~~~~~~~~~~~~^~
towns.cpp:64:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(qan[ds].size()>hx){
~~~~~~~~~~~~~~^~~
towns.cpp:66:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j>=qan[ds].size())ok=true;
~^~~~~~~~~~~~~~~~
towns.cpp:49:6: warning: unused variable 'hwx' [-Wunused-variable]
int hwx=1;
^~~
towns.cpp:16: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... |