이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
long long min_distance(std::vector <int> a, std::vector <int> h,
std::vector <int> l, std::vector <int> r, std::vector <int> y,
int s, int e) {
if (e < s) {
std::swap(s, e);
}
int n = a.size();
int m = y.size();
std::vector <std::vector <std::pair <int, bool>>> inds(n + 1);
for (int i = 0; i < m; i++) {
inds[l[i]].emplace_back(y[i], true);
inds[r[i] + 1].emplace_back(y[i], false);
}
inds[1].emplace_back(0, false);
std::map <int, long long> mp;
mp[0] = 0;
std::set <int> st;
for (int i = 0; i < n; i++) {
for (auto p : inds[i]) {
if (!p.second && !st.count(p.first)) {
mp.erase(p.first);
}
}
st.clear();
for (auto p : inds[i]) {
if (p.second) {
auto it = mp.lower_bound(p.first);
long long val = 1LL << 60;
if (it != mp.end()) {
val = std::min(val, it->second - p.first + it->first);
}
if (it != mp.begin()) {
it--;
val = std::min(val, it->second - it->first + p.first);
}
if (val != (1LL << 60)) {
mp[p.first] = val;
st.insert(p.first);
}
}
}
}
if (mp.empty()) {
return -1;
}
return mp.begin()->first + mp.begin()->second + a[n - 1] - a[0];
}
# | 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... |