Submission #434234

#TimeUsernameProblemLanguageResultExecution timeMemory
434234emil_physmathSky Walking (IOI19_walk)C++17
24 / 100
1769 ms361008 KiB
#define BUGO(x) cerr << #x << " -> " << (x) << endl; #include "walk.h" #include <algorithm> #include <iostream> #include <numeric> #include <vector> #include <queue> #include <set> #include <map> using namespace std; using llong = long long; vector<pair<int, int>> nei[6900'000]; llong dist[6900'000]; llong Dijkstra(int s, int e) { const llong inf = 69'000'000'000'000'000LL; fill(dist, dist + 6900'000, inf); priority_queue<pair<llong, int>> q; q.push({dist[s] = 0, s}); while (q.size()) { int v = q.top().second; llong d = -q.top().first; q.pop(); if (dist[v] != d) continue; for (auto to: nei[v]) if (d + to.second < dist[to.first]) q.push({-(dist[to.first] = d + to.second), to.first}); } return dist[e] == inf ? -1 : dist[e]; } map<int, int> nodeOf[100'000]; long long min_distance(std::vector<int> x, std::vector<int> y, std::vector<int> l, std::vector<int> r, std::vector<int> h, int s, int e) { int n = x.size(); int m = l.size(); int nodes = 0; for (int i = 0; i < n; ++i) nodeOf[i][y[i]] = nodes++; nodeOf[s][0] = nodes++; nodeOf[e][0] = nodes++; bool smallTest = (n <= 50 && m <= 50) || y != vector<int>(n, y[0]); vector<int> towers(n); iota(towers.begin(), towers.end(), 0); sort(towers.begin(), towers.end(), [&](int l, int r) { return y[l] < y[r]; }); vector<int> bridges(m); iota(bridges.begin(), bridges.end(), 0); sort(bridges.begin(), bridges.end(), [&](int l, int r) { return h[l] < h[r]; }); set<int> activeTowers; for (int tch = m - 1; tch >= 0; --tch) { int j = bridges[tch]; while (towers.size() && y[towers.back()] >= h[j]) { activeTowers.insert(towers.back()); towers.pop_back(); } int lt = -1; for (auto it = activeTowers.lower_bound(l[j]); it != activeTowers.end() && *it <= r[j]; ) { int i = *it; if (!nodeOf[i].count(h[j])) nodeOf[i][h[j]] = nodes++; if (lt != -1) { int u = nodeOf[i][h[j]]; int v = nodeOf[lt][h[j]]; nei[u].push_back({v, x[i] - x[lt]}); nei[v].push_back({u, x[i] - x[lt]}); } lt = i; if (smallTest) ++it; else if (*it == l[j]) it = activeTowers.lower_bound(r[j]); else break; } } for (int i = 0; i < n; ++i) { int ltHei = -1; for (auto [hei, node]: nodeOf[i]) { if (ltHei != -1) { int u = nodeOf[i][ltHei]; int v = node; nei[u].push_back({v, hei - ltHei}); nei[v].push_back({u, hei - ltHei}); } ltHei = hei; } } return Dijkstra(n, n + 1); }
#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...