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"
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a:b)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
const int MX = 115;
int n;
int mem[MX][MX];
int getD(int x, int y) {
if(mem[x][y] != -1) return mem[x][y];
return mem[x][y] = mem[y][x] = getDistance(x,y);
}
int hubDistance(int N, int sub) {
n = N;
RE(i,n) RE(j,n) mem[i][j] = -1;
RE(i,n) mem[i][i] = 0;
int x = 0, y = 0, pathL = 0;
REP(i,1,n) {
int d = getD(x,i);
if(d > pathL) {
pathL = d;
y = i;
}
}
RE(i,n) {
int d = getD(y,i);
if(d > pathL) {
pathL = d;
x = i;
}
}
map<int, int> fromX;
RE(i,n) {
if(i == x || i == y) continue;
int dx = getD(i,x);
int dy = getD(i,y);
int lenI = (dx+dy-pathL)/2;
fromX[dx-lenI] = max(fromX[dx-lenI], max(dx-lenI, max(dy-lenI, lenI)));
}
int disX = fromX.begin()->fi;
int ans = fromX.begin()->se;
FOR(p,fromX) {
if(p.se < ans) {
ans = p.se;
disX = p.fi;
}
}
int cnt[3];
RE(i,3) cnt[i] = 0;
RE(i,n) {
if(i == x || i == y) continue;
int dx = getD(i,x);
int dy = getD(i,y);
int lenI = (dx+dy-pathL)/2;
int cdx = dx-lenI;
if(cdx < disX) {
cnt[0]++;
} else if(cdx > disX) {
cnt[1]++;
} else {
cnt[2]++;
}
}
cnt[0]++; cnt[1]++;
bool bal = 1;
RE(i,3) if(cnt[i] > n/2) bal = 0;
if(!bal) ans = -ans;
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:38:28: warning: unused parameter 'sub' [-Wunused-parameter]
38 | 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... |