이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
#include "towns.h"
int hubDistance(int N, int sub) {
int a = -1;
int maxd = -1;
for (int i = 0; i < N; i++) {
int cdist = getDistance(0, i);
if (cdist > maxd) {
a = i;
maxd = cdist;
}
}
int b = -1;
maxd = -1;
vi dist1(N, -1);
for (int i = 0; i < N; i++) {
dist1[i] = getDistance(a, i);
if (dist1[i] > maxd) {
b = i;
maxd = dist1[i];
}
}
vi dist2(N, -1);
for (int i = 0; i < N; i++) {
dist2[i] = getDistance(b, i);
}
int dia = dist1[b];
// cout<<"a, b, dia: "<<a<<", "<<b<<"; "<<dia<<endl;
int ans = 1e9;
for (int i = 0; i < N; i++) {
int s = (dia + abs(dist1[i] - dist2[i])) / 2;
ans = min(ans, s);
}
vi cen;
map<int, int> cnts;
for (int i = 0; i < N; i++) {
cnts[dist1[i] - dist2[i]]++;
}
/* cout<<"cnts: "<<endl;
for (ii p : cnts)
cout<<p.fi<<": "<<p.se<<endl;*/
int ctr = 0;
for (ii p : cnts) {
if (((dia + abs(p.fi)) / 2 == ans) && (p.se <= N / 2) && (ctr <= N / 2) && (N - p.se - ctr <= N / 2))
return ans;
ctr += p.se;
}
return -ans;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:15:28: warning: unused parameter 'sub' [-Wunused-parameter]
15 | 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... |