이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "walk.h"
using ll = long long;
template <class T> using Vec = std::vector<T>;
constexpr ll INF = std::numeric_limits<ll>::max() / 2;
ll min_distance(Vec<int> x, Vec<int> h, Vec<int> l, Vec<int> r, Vec<int> y, int s, int g) {
const int n = (int) x.size();
const int m = (int) y.size();
if (s == 0 and g == n - 1) {
Vec<Vec<int>> start(n), end(n);
for (int i = 0; i < m; ++i) {
start[l[i]].push_back(i);
end[r[i]].push_back(i);
}
std::map<int, ll> map;
std::multiset<int> alive;
for (const auto i: start[0]) {
map[y[i]] = y[i];
alive.insert(y[i]);
}
for (int i = 1; i < n; ++i) {
for (const auto j: start[i]) {
if (alive.find(y[j]) == alive.end()) {
auto itr = map.lower_bound(y[j]);
ll d = INF;
if (itr != map.end() and h[i] >= itr -> first) {
d = std::min(d, itr -> second + (itr -> first - y[j]));
}
if (itr != map.begin()) {
--itr;
d = std::min(d, itr -> second + (y[j] - itr -> first));
}
map.emplace(y[j], d);
}
alive.insert(y[j]);
}
if (i != n - 1) {
for (const auto j: end[i]) {
alive.erase(alive.find(y[j]));
if (alive.find(y[j]) == alive.end()) {
map.erase(y[j]);
}
}
}
}
ll ret = INF;
for (const auto [y, d]: map) {
ret = std::min(ret, y + d);
}
return (ret == INF ? -1 : ret + (x[n - 1] - x[0]));
}
return -1;
}
# | 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... |