#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;
for (const auto i: start[0]) {
map[y[i]] = y[i];
}
std::multiset<int> alive;
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()) {
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]);
}
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);
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
5960 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
5960 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |