이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "walk.h"
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
int n = x.size();
int m = y.size();
multiset<pair<int, long long>> st;
vector<int> add[n], rem[n];
for (int i = 0; i < m; i++) {
add[l[i]].push_back(i);
rem[r[i]].push_back(i);
}
vector<long long> ans(m);
for (int i = 0; i < n; i++) {
vector<pair<int, int>> nw;
for (int j : add[i]) {
if (i == 0) nw.push_back({y[j], y[j]}), ans[j] = y[j];
else {
long long v = 1e18;
auto up = st.upper_bound({y[j], -5});
if (up != st.end()) v = min(v, (*up).first - y[j] + (*up).second);
auto down = st.lower_bound({y[j], -5});
if (!st.empty() && up == down && down != st.begin()) {
down--;
v = min(v, y[j] - (*down).first + (*down).second);
}
ans[j] = v;
nw.push_back({y[j], ans[j]});
}
}
for (auto x : nw) st.insert(x);
for (int j : rem[i]) if (st.find({y[j], ans[j]}) != st.end()) st.erase(st.find({y[j], ans[j]}));
}
long long ret = 1e18;
for (int i = 0; i < m; i++) {
if (r[i] == n - 1) ret = min(ret, ans[i] + y[i] + x[n - 1] - x[0]);
}
if (ret == 1e18) ret = -1;
return ret;
}
# | 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... |