이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1LL<<60;
int n;
map<pair<int,int>,int> cache;
int getdist(int u, int v) {
if (u==v) {
return 0;
}
if (u>v) swap(u,v);
if (cache.count({u,v})) {
return cache[{u,v}];
}
return cache[{u,v}] = getDistance(u,v);
}
signed hubDistance(signed N, signed sub) {
n=N;
vector<int> dist0(n);
for (int i=0; i<n; i++) {
dist0[i] = getdist(0,i);
}
vector<int> cities(n); iota(cities.begin(), cities.end(), (int)0);
vector<int> sortedbyd0(cities.begin(), cities.end());
sort(sortedbyd0.begin(), sortedbyd0.end(), [&](const int i1, const int i2) {
return dist0[i1]<dist0[i2];
});
int u = sortedbyd0.back();
vector<int> distu(n);
for (int i=0; i<n; i++) {
distu[i] = getdist(u,i);
}
//2n-3 used
vector<int> sortedbydu(cities.begin(), cities.end());
sort(sortedbydu.begin(), sortedbydu.end(), [&](const int i1, const int i2) {
return distu[i1]<distu[i2];
});
int v = sortedbydu.back();
//u-v is a diameter
int length = distu[v];
int mindiff = INF;
for (int i=0; i<n; i++) {
mindiff = min(mindiff,abs(getdist(i,u)-getdist(i,v)));
}
return (length+mindiff)/2;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'long long int getdist(long long int, long long int)':
towns.cpp:19:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
19 | return cache[{u,v}] = getDistance(u,v);
| ^
towns.cpp:19:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
19 | return cache[{u,v}] = getDistance(u,v);
| ^
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:53:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
53 | return (length+mindiff)/2;
| ~~~~~~~~~~~~~~~~^~
towns.cpp:22:37: warning: unused parameter 'sub' [-Wunused-parameter]
22 | signed hubDistance(signed N, signed 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... |