Submission #838972

#TimeUsernameProblemLanguageResultExecution timeMemory
838972tch1cherinJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
259 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]}); } } queue<int> Q; vector<int> dist(N, INT_MAX); dist[B[0]] = 0; Q.push(B[0]); while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto [v, w] : G[u]) { if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; Q.push(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...