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;
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define ft first
#define nd second
#define pb push_back
const int INF = 1e9 + 7;
int hubDistance(int N, int sub) {
int dist[N][N];
for (int i = 0; i < N; i++){
dist[i][i] = 0;
for (int j = i + 1; j < N; j++){
dist[i][j] = dist[j][i] = getDistance(i, j);
}
}
int ans = INF;
for (int i = 0; i < N; i++){
for (int j = i + 1; j < N; j++){
int d1 = (dist[1][i] - dist[1][j] + dist[i][j]) / 2;
int d2 = dist[i][j] - d1;
int curr = max(d1, d2);
for (int k = 0; k < N; k++){
int x1 = dist[k][i] - d1, x2 = dist[k][j] - d2;
curr = max(curr, max(x1, x2));
}
//cout<<i<<sp<<j<<sp<<curr<<endl;
ans = min(ans, curr);
}
}
int flag = 0;
for (int i = 0; i < N; i++){
for (int j = i + 1; j < N; j++){
int d1 = (dist[1][i] - dist[1][j] + dist[i][j]) / 2;
int d2 = dist[i][j] - d1;
int curr = max(d1, d2);
for (int k = 0; k < N; k++){
int x1 = dist[k][i] - d1, x2 = dist[k][j] - d2;
curr = max(curr, max(x1, x2));
}
if (ans != curr) continue;
vector<int> vis(N, 0);
int maks = 1, sz1 = 1, sz2 = 1;
for (int k = 0; k < N; k++){
if (vis[k]) continue;
int x1 = dist[k][i] - d1, x2 = dist[k][j] - d2;
if (x1 == x2){
int sz = 1;
for (int l = 0; l < N; l++){
if (vis[l]) continue;
int y1 = dist[l][i] - d1, y2 = dist[l][k] - x1;
if (y1 > y2){
sz++;
vis[l] = 1;
}
}
maks = max(maks, sz);
}
else if (x1 < x2) sz1++;
else sz2++;
}
maks = max(maks, sz1);
maks = max(maks, sz2);
if (maks <= N / 2) flag = 1;
}
}
if (flag) return ans;
return -ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:14:28: warning: unused parameter 'sub' [-Wunused-parameter]
14 | 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... |