Submission #298492

#TimeUsernameProblemLanguageResultExecution timeMemory
298492JPN20Sky Walking (IOI19_walk)C++17
24 / 100
1513 ms354792 KiB
#include "walk.h" #include <bits/stdc++.h> using namespace std; // Input long long N, X[1 << 18], H[1 << 18]; long long M, L[1 << 18], R[1 << 18], Y[1 << 18]; long long SX, GX; // Compress vector<pair<long long, long long>> V[1 << 18]; set<pair<long long, long long>> Set; vector<tuple<long long, long long, long long>> tup; // Graph int I; long long dist[1400000]; vector<pair<long long, long long>> G[1400000]; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> Q; long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) { N = x.size(); M = l.size(); SX = s; GX = g; for (int i = 0; i < N; i++) X[i] = x[i]; for (int i = 0; i < N; i++) H[i] = h[i]; for (int i = 0; i < M; i++) L[i] = l[i]; for (int i = 0; i < M; i++) R[i] = r[i]; for (int i = 0; i < M; i++) Y[i] = y[i]; // Step #1. Maeshori for (int i = 0; i < N; i++) tup.push_back(make_tuple(H[i], 2, i)); for (int i = 0; i < M; i++) tup.push_back(make_tuple(Y[i], 1, i)); sort(tup.begin(), tup.end()); reverse(tup.begin(), tup.end()); // Step #2. Make Graph I = N; for (int i = 0; i < (int)tup.size(); i++) { if(get<1>(tup[i]) == 1) { int idx = get<2>(tup[i]); auto itr = Set.lower_bound(make_pair(X[L[idx]], L[idx])); vector<pair<int, int>> vec; while (itr != Set.end()) { pair<int, int> val = (*itr); if(val.first > X[R[idx]]) break; vec.push_back(make_pair(I, val.first)); V[val.second].push_back(make_pair(get<0>(tup[i]), I)); I += 1; itr++; } for (int j = 0; j < (int)vec.size() - 1; j++) { long long dst = (vec[j + 1].second - vec[j + 0].second); G[vec[j + 0].first].push_back(make_pair(vec[j + 1].first, dst)); G[vec[j + 1].first].push_back(make_pair(vec[j + 0].first, dst)); } } if(get<1>(tup[i]) == 2) { int idx = get<2>(tup[i]); Set.insert(make_pair(X[idx], idx)); } } // Step #3. Make Graph 2 for (int i = 0; i < N; i++) V[i].push_back(make_pair(0, i)); for (int i = 0; i < N; i++) { sort(V[i].begin(), V[i].end()); for (int j = 0; j < (int)V[i].size() - 1; j++) { int to1 = V[i][j].second; int to2 = V[i][j + 1].second; long long dst = V[i][j + 1].first - V[i][j].first; G[to1].push_back(make_pair(to2, dst)); G[to2].push_back(make_pair(to1, dst)); } } // Step #4. Dijkstra for (int i = 0; i < I; i++) dist[i] = (1LL << 60); dist[SX] = 0; Q.push(make_pair(0, SX)); while (!Q.empty()) { int pos = Q.top().second; Q.pop(); for (int i = 0; i < (int)G[pos].size(); i++) { int to = G[pos][i].first; long long cost = G[pos][i].second; if (dist[to] > dist[pos] + cost) { dist[to] = dist[pos] + cost; Q.push(make_pair(dist[to], to)); } } } if (dist[GX] == (1LL << 60)) return -1; return dist[GX]; }
#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...