이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "towns.h"
int maxind(VL& a) {
int ret;
ll mx = -1e18;
rep(i, a.size()) if (a[i] > mx) {
mx = a[i];
ret = i;
}
return ret;
}
int hubDistance(int N, int SUBTASK) {
int n = N;
VL dist0, distd1, distd2, distl, distr;
dist0 = distd1 = distd2 = distl = distr = VL(n);
rep(u, n) dist0[u] = getDistance(0, u);
int d1 = maxind(dist0);
rep(u, n) distd1[u] = getDistance(d1, u);
int d2 = maxind(distd1);
rep(u, n) distd2[u] = getDistance(d2, u);
ll R = 1e18;
rep(u, n) {
ll d = (distd1[u] + distd2[u] - distd1[d2])/2;
distl[u] = distd1[u]-d;
distr[u] = distd2[u]-d;
setmin(R, max(distl[u], distr[u]));
}
VI anc(n);
/* 0, on the left
* 1, first hub
* 2, second hub
* 3, on the right
*/
rep(u, n) {
if (max(distl[u], distr[u]) == R) {
if (distl[u] <= distr[u]) anc[u] = 1;
else anc[u] = 2;
} else {
if (distl[u] <= distr[u]) anc[u] = 0;
else anc[u] = 3;
}
}
int cnt[4]{};
for (int x : anc) cnt[x]++;
if (cnt[0] <= N/2 && cnt[1] <= N/2 && cnt[2] + cnt[3] <= N/2) return +R;
if (cnt[0] + cnt[1] <= N/2 && cnt[2] <= N/2 && cnt[3] <= N/2) return +R;
return -R;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:80:74: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
80 | if (cnt[0] <= N/2 && cnt[1] <= N/2 && cnt[2] + cnt[3] <= N/2) return +R;
| ^~
towns.cpp:81:74: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
81 | if (cnt[0] + cnt[1] <= N/2 && cnt[2] <= N/2 && cnt[3] <= N/2) return +R;
| ^~
towns.cpp:82:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
82 | return -R;
| ^~
towns.cpp:44:28: warning: unused parameter 'SUBTASK' [-Wunused-parameter]
44 | int hubDistance(int N, int SUBTASK) {
| ~~~~^~~~~~~
towns.cpp: In function 'int maxind(VL&)':
towns.cpp:41:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | return ret;
| ^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:52:38: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | rep(u, n) distd2[u] = getDistance(d2, u);
| ~~~~~~~~~~~^~~~~~~
towns.cpp:50:38: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | rep(u, n) distd1[u] = getDistance(d1, u);
| ~~~~~~~~~~~^~~~~~~
# | 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... |