Submission #390922

#TimeUsernameProblemLanguageResultExecution timeMemory
390922SuhaibSawalha1Sky Walking (IOI19_walk)C++17
10 / 100
4081 ms162216 KiB
#include "walk.h" #include <bits/stdc++.h> using namespace std; int dist (array<int, 2> &a, array<int, 2> &b) { return abs(a[0] - b[0]) + abs(a[1] - b[1]); } 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 src, int snk) { vector<array<int, 2>> p; int n = x.size(), m = y.size(); vector<vector<int>> seg(n + m), adj((int)1e6); auto add = [&] (int i) { adj[p.size()].push_back(i); seg[i].push_back(p.size()); }; for (int i = 0; i < n; ++i) { add(i); p.push_back({x[i], 0}); add(i); p.push_back({x[i], h[i]}); } for (int i = 0; i < m; ++i) { add(l[i]); add(n + i); p.push_back({x[l[i]], y[i]}); add(r[i]); add(n + i); p.push_back({x[r[i]], y[i]}); for (int j = l[i]; j <= r[i]; ++j) { if (h[j] >= y[i]) { add(j); add(n + i); p.push_back({x[j], y[i]}); } } } priority_queue<pair<long long, int>> pq; pq.push({0, 2 * src}); vector<long long> dis(adj.size(), 1e18); dis[2 * src] = 0; while (pq.size()) { long long d = -pq.top().first; int u = pq.top().second; pq.pop(); if (d != dis[u]) { continue; } for (int e : adj[u]) { for (int v : seg[e]) { int dd = dist(p[u], p[v]); if (d + dd < dis[v]) { dis[v] = d + dd; pq.push({-dis[v], v}); } } } } return dis[2 * snk] == 1e18 ? -1 : dis[2 * snk]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...