| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 890240 | vjudge1 | Sky Walking (IOI19_walk) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<ll>;
using ll = long long;
using ii = pair<ll, ll>;
struct Dijkstra {
vector<vector<ii> > L;
ll n;
Dijkstra(ll N) : n(N), L(N) {}
void add_edge(ll u, ll v, ll w) {
L[u].push_back({v, w});
L[v].push_back({u, w});
}
ll dist(ll s, ll t) {
const ll INF = 1e18;
vector<ll> D(n, INF);
D[s] = 0;
priority_queue<pair<ll, ll> > PQ;
PQ.push({0, s});
while(!PQ.empty()) {
ll u = PQ.top().second;
ll d = - PQ.top().first;
PQ.pop();
if(D[u] != d) continue;
for(auto [it, w] : L[u]) {
if(D[it] > D[u] + w) {
D[it] = D[u] + w;
PQ.push({-D[it], it});
}
}
}
if(D[t] == INF) D[t] = -1;
return D[t];
}
};
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
ll n = x.size();
ll tmr = 0;
vector<vector<pair<ll, ll> > > Noduri(n); /// perechi(id, h)
vector<tuple<ll, ll, ll> > E;
for(ll i = 0; i < n; ++i) {
Noduri[i].push_back({tmr++, 0});
}
for(ll i = 0; i < l.size(); ++i) {
ll ult = -1;
for(ll j = l[i]; j <= r[i]; ++j) {
if(h[j] < y[i]) continue;
else {
Noduri[j].push_back({tmr++, y[i]});
if(ult != -1) {
E.emplace_back(tmr - 1, Noduri[ult].back().first, x[j] - x[ult]);
}
ult = j;
}
}
}
Dijkstra Sol(tmr);
for(auto [u, v, w] : E)
Sol.add_edge(u, v, w);
for(ll i = 0; i < n; ++i) {
sort(Noduri[i].begin(), Noduri[i].end(), [&](auto a, auto b) {return a.second < b.second;});
for(ll j = 0; j + 1 < Noduri[i].size(); ++j) {
Sol.add_edge(Noduri[i][j].first, Noduri[i][j + 1].first,
Noduri[i][j + 1].second - Noduri[i][j].second);
}
}
return Sol.dist(Noduri[s][0].first, Noduri[g][0].first);
}
