이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
map<pii, int> memo;
int dist(int i, int j) {
if (i > j) {
swap(i, j);
}
if (!memo[{i, j}]) {
memo[{i, j}] = getDistance(i, j);
}
return memo[{i, j}];
}
void findLocation(int N, int first, int location[], int stype[]) {
location[0] = first;
stype[0] = 1;
int closest = 1, mindist = dist(0, 1);
ffor(i, 2, N) {
if (dist(0, i) < mindist) {
mindist = dist(0, i);
closest = i;
}
}
location[closest] = first + dist(0, closest);
stype[closest] = 2;
vpii left, right;
ffor(i, 1, N) {
if (i != closest) {
if (dist(0, i) == dist(0, closest) + dist(closest, i)) {
left.emplace_back(dist(closest, i), i);
} else {
right.emplace_back(dist(0, i), i);
}
}
}
sort(all(left));
sort(all(right));
int front = 0, back = closest;
forin(p, right) {
int i = p.second;
if (first + dist(0, i) + location[back] - 2 * location[front] == dist(back, i)) {
location[i] = first + dist(0, i);
stype[i] = 2;
back = i;
} else {
location[i] = location[back] - dist(back, i);
stype[i] = 1;
front = i;
}
}
front = closest, back = 0;
forin(p, left) {
int i = p.second;
if (-location[closest] + dist(closest, i) - location[back] + 2 * location[front] == dist(back, i)) {
location[i] = location[closest] - dist(closest, i);
stype[i] = 1;
back = i;
} else {
location[i] = location[back] + dist(back, i);
stype[i] = 2;
front = i;
}
}
}
# | 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... |