이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 2e8 + 10;
int n, d[110][110];
int cnt[110];
int Dis(int v, int u){
if (v == u or d[v][u] > 0)
return d[v][u];
return d[v][u] = d[u][v] = getDistance(v,u);
}
int getDis(int v, int u, int w){
return (Dis(v,u)+Dis(v,w)-Dis(u,w))/2;
}
int hubDistance(int N, int sub){
memset(d, 0, sizeof d);
n = N;
int Q1 = 0, Q2 = 0;
for (int i = 1; i < n; i++)
if (Dis(0,i) > Dis(0,Q1))
Q1 = i;
for (int i = 1; i < n; i++)
if (Dis(Q1,i) > Dis(Q1,Q2))
Q2 = i;
int R = inf;
vector<int> a;
for (int v = 0; v < n; v++){
if (v == Q1 or v == Q2)
continue;
int A = getDis(Q1, Q2, v), B = getDis(Q2, Q1, v);
a.push_back(A);
R = min(R,max(A,B));
}
sort(a.begin(), a.end());
a.resize(unique(a.begin(),a.end())-a.begin());
int m = 1;
for (auto it : a){
int now = 0;
vector<int> b;
for (int v = 0; v < n; v++){
if (v == Q1 or v == Q2)
continue;
if (getDis(Q1, Q2, v) == it)
now ++, b.push_back(v);
}
int t = max(it,Dis(Q1,Q2)-it);
if (t != R or m > n/2 or (n-m-now) > n/2){
m += now;
continue;
}
if (now <= n/2)
return R;
memset(cnt, 0, sizeof cnt);
vector<int> nom;
shuffle(b.begin(), b.end(), rng);
nom.push_back(b[0]);
cnt[b[0]] ++;
int Constant = 50, check = -1;
for (int i = 1; i < now; i++){
if (i <= Constant){
bool found = 0;
for (auto j : nom)
if (getDis(Q1,j,b[i]) > it)
cnt[j] ++, found = 1;
if (!found)
nom.push_back(b[i]), cnt[b[i]] ++;
if (i == Constant){
sort(nom.begin(), nom.end(), [](int x, int y){return cnt[x] > cnt[y];});
check = nom[0];
}
}
else{
if (getDis(Q1,check,b[i]) == it)
cnt[check] ++;
}
}
if (cnt[check] <= n/2)
return R;
m += now;
}
return -R;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:19:28: warning: unused parameter 'sub' [-Wunused-parameter]
19 | 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... |