Submission #774882

#TimeUsernameProblemLanguageResultExecution timeMemory
774882t6twotwoSky Walking (IOI19_walk)C++17
10 / 100
4111 ms707312 KiB
#include "walk.h" #include <bits/stdc++.h> using namespace std; using ll = long long; ll min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int s, int g) { int N = X.size(); int M = Y.size(); map<pair<int, int>, int> mp; vector<pair<int, int>> p; for (int i = 0; i < N; i++) { mp[{X[i], 0}] = i; p.emplace_back(X[i], 0); } vector<vector<pair<int, int>>> adj(N); for (int i = 0; i < M; i++) { for (int j = L[i], k = -1; j <= R[i]; j++) { if (H[j] >= Y[i]) { int q; if (!mp.count({X[j], Y[i]})) { mp[{X[j], Y[i]}] = q = p.size(); p.emplace_back(X[j], Y[i]); adj.push_back({}); } else { q = mp[{X[j], Y[i]}]; } if (k != -1) { adj[k].emplace_back(q, X[j] - p[k].first); adj[q].emplace_back(k, X[j] - p[k].first); } k = q; } } } int q = -1; for (auto [P, k] : mp) { auto [x, y] = P; if (q != -1 && p[q].first == x) { adj[k].emplace_back(q, y - p[q].second); adj[q].emplace_back(k, y - p[q].second); } q = k; } int K = adj.size(); vector<ll> dis(K, -1); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.emplace(0, s); while (!pq.empty()) { auto [d, x] = pq.top(); pq.pop(); if (dis[x] != -1) { continue; } dis[x] = d; for (auto [y, z] : adj[x]) { pq.emplace(d + z, y); } } return dis[g]; }
#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...