이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define X first
#define Y second
int v = 0, s, t, r;
int distv[120], dists[120];
bool sameConn(int x1, int x2) {
int x = getDistance(x1, x2);
return (dists[x1] + dists[x2] - x > 2 * r);
}
int hubDistance(int N, int sub) {
int maxv = 0;
for(int i = 0 ; i < N ; i++) {
distv[i] = getDistance(v, i);
maxv = max(maxv, distv[i]);
}
for(int i = 0 ; i < N ; i++)
if(distv[i] == maxv)
s = i;
int dsv = maxv;
maxv = 0;
for(int i = 0 ; i < N ; i++) {
dists[i] = getDistance(s, i);
maxv = max(maxv, dists[i]);
}
int d = maxv;
for(int i = 0 ; i < N ; i++)
if(dists[i] == maxv)
t = i;
int res = 1e9;
for(int i = 0 ; i < N ; i++) {
int a = (dists[i] + dsv - distv[i]) / 2;
int b = dsv - a;
if(max({a, b, d - a}) < res) {
res = max({a, b, d - a});
r = a;
}
//~ cout << i << " " << res << endl;
}
vector<int> B;
for(int i = 0 ; i < N ; i++)
B.push_back((dists[i] + dsv - distv[i]) / 2);
sort(B.begin(), B.end());
int m;
if(B.size() % 2 == 0) {
int m1 = B[B.size() / 2 - 1];
int m2 = B[B.size() / 2];
if(m1 == m2)
m = m1;
else
return res;
} else
m = B[B.size() / 2];
if(r != m)
return -res;
vector<ii> X, D;
for(int i = 0 ; i < N ; i++)
if((dists[i] + dsv - distv[i]) / 2 == m)
X.push_back({i, 1});
while(X.size() > 1) {
if(X.size() % 2)
X.pop_back();
else {
vector<ii> Y;
for(int i = 0 ; i < X.size() ; i += 2) {
if(sameConn(X[i].X, X[i + 1].X))
Y.push_back({X[i].X, X[i].Y + X[i + 1].Y});
else {
D.push_back(X[i]);
D.push_back(X[i + 1]);
}
}
swap(X, Y);
}
}
if(X.empty())
return res;
int cnt = X[0].Y;
for(auto p : D) {
if(sameConn(p.X, X[0].X))
cnt += p.Y;
}
if(cnt <= N / 2)
return res;
return -res;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:85:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < X.size() ; i += 2) {
~~^~~~~~~~~~
towns.cpp:19: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... |