Submission #838944

#TimeUsernameProblemLanguageResultExecution timeMemory
838944tch1cherinJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
273 ms262144 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; vector<vector<pair<int, int>>> G(N); vector<int> B(M), P(M); for (int i = 0; i < M; i++) { cin >> B[i] >> P[i]; for (int j = B[i] % P[i]; j < N; j += P[i]) { G[B[i]].push_back({j, abs(B[i] - j) / P[i]}); } } min_heap<pair<int, int>> Q; vector<int> dist(N, INT_MAX); dist[B[0]] = 0; Q.push({0, B[0]}); while (!Q.empty()) { auto [d, u] = Q.top(); Q.pop(); if (d > dist[u]) { continue; } for (auto [v, w] : G[u]) { if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; Q.push({dist[v], v}); } } } cout << (dist[B[1]] == INT_MAX ? -1 : dist[B[1]]) << "\n"; }
#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...