제출 #838971

#제출 시각아이디문제언어결과실행 시간메모리
838971tch1cherinJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms468 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]) { assert(dist[v] == INT_MAX); 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...