이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
int min_distance(vector<signed> x, vector<signed> h, vector<signed> l,
vector<signed> r, vector<signed> y, signed v_start, signed v_end) {
int n_build = x.size(), n_sky = y.size();
vector<pii> xy; // {x, y}
vector<vector<pii>> stick(n_build); // {y, id}
vector<vector<pii>> g; // {v, dst}
for (int i = 0; i < n_sky; i++) {
for (int b = l[i]; b <= r[i]; b++) {
int lst;
if (y[i] <= h[b]) {
stick[b].push_back({y[i], xy.size()});
xy.push_back({x[b], y[i]});
g.emplace_back();
if (b != l[i]) {
g.back().push_back({xy.size() - 2, x[b] - x[lst]});
g[xy.size() - 2].push_back({xy.size() - 1, x[b] - x[lst]});
}
lst = b;
}
}
}
for (int i = 0; i < n_build; i++) {
stick[i].push_back({0, g.size()});
g.emplace_back();
xy.push_back({x[i], 0});
sort(stick[i].begin(), stick[i].end());
for (int j = 0; j < (int) stick[i].size() - 1; j++) {
int dst = stick[i][j + 1].first - stick[i][j].first;
g[stick[i][j].second].push_back({stick[i][j + 1].second, dst});
g[stick[i][j + 1].second].push_back({stick[i][j].second, dst});
}
}
int n_vert = xy.size();
vector<int> d(n_vert, 1e17);
d[n_vert - n_build + v_start] = 0;
priority_queue<pii, vector<pii>, greater<pii>> q;
q.push({0, n_vert - n_build + v_start});
while (!q.empty()) {
auto [dv, v] = q.top();
q.pop();
if (d[v] < dv) continue;
for (auto [u, dvu] : g[v]) {
if (dvu + dv < d[u]) {
d[u] = dvu + dv;
q.push({d[u], u});
}
}
}
return d[n_vert - n_build + v_end];
}
컴파일 시 표준 에러 (stderr) 메시지
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | auto [dv, v] = q.top();
| ^
walk.cpp:54:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for (auto [u, dvu] : g[v]) {
| ^
walk.cpp:23:68: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
23 | g.back().push_back({xy.size() - 2, x[b] - x[lst]});
| ^
# | 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... |