이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int dist[5005][5005];
void findLocation(int N, int first, int location[], int stype[]) {
vector<int> left, right;
vector<vector<int> > dist(N, vector<int>(N));
location[0] = first;
stype[0] = 1;
dist[0][0] = 0;
for (int i = 1; i < N; i++) {
dist[0][i] = getDistance(0, i);
}
int X = min_element(dist[0].begin() + 1, dist[0].end()) - dist[0].begin(), Y = 0;
stype[X] = 2;
location[X] = first + dist[0][X];
for (int i = 0; i < N; i++) {
if (i == 0 || i == X) {
continue;
}
dist[X][i] = getDistance(X, i);
if (dist[X][i] < dist[0][X]) {
stype[i] = 1;
location[i] = location[X] - dist[X][i];
if (location[Y] < location[i]) {
Y = i;
}
} else if (dist[0][X] + dist[X][i] == dist[0][i]) {
// left side
left.pb(i);
} else {
// right side
right.pb(i);
}
}
// handle left side
if (!left.empty()) {
map<int, int> processed;
sort(left.begin(), left.end(), [&](const int &lhs, const int &rhs) {
return dist[X][lhs] < dist[X][rhs];
});
int cl = left[0];
location[cl] = location[X] - dist[X][cl];
stype[cl] = 1;
processed[location[cl]] = stype[cl];
for (int i = 1; i < (int)left.size(); i++) {
int cur = left[i];
int tmp = getDistance(cl, cur);
int v = dist[X][cl] + tmp - dist[X][cur];
assert(v % 2 == 0);
if (processed.find(location[cl] + v / 2) == processed.end() || processed[location[cl] + v / 2] == 2) {
location[cur] = location[cl] - (tmp - v);
stype[cur] = 1;
cl = cur;
} else {
location[cur] = location[cl] + tmp;
stype[cur] = 2;
}
processed[location[cur]] = stype[cur];
}
}
// handle right side
if (!right.empty()) {
for (int i = 0; i < N; i++) {
dist[Y][i] = dist[0][i] - (location[Y] - location[0]);
}
map<int, int> processed;
sort(right.begin(), right.end(), [&](const int &lhs, const int &rhs) {
return dist[Y][lhs] < dist[Y][rhs];
});
int cl = right[0];
location[cl] = location[Y] + dist[Y][cl];
stype[cl] = 2;
processed[location[cl]] = stype[cl];
for (int i = 1; i < (int)right.size(); i++) {
int cur = right[i];
int tmp = getDistance(cl, cur);
int v = dist[Y][cl] + tmp - dist[Y][cur];
assert(v % 2 == 0);
if (processed.find(location[cl] - v / 2) == processed.end() || processed[location[cl] - v / 2] == 2) {
location[cur] = location[cl] + (tmp - v);
stype[cur] = 2;
cl = cur;
} else {
location[cur] = location[cl] - tmp;
stype[cur] = 1;
}
processed[location[cur]] = stype[cur];
}
}
}
# | 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... |