제출 #400765

#제출 시각아이디문제언어결과실행 시간메모리
400765BERNARB01Jakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, long long>>> g(n); int target = -1; for (int i = 0; i < n; i++) { int b, p; cin >> b >> p; if (i == 1) { target = b; } for (int j = 0; j < n; j++) { int d = abs(b - j); if (d % p == 0) { g[b].emplace_back(j, d / p); } } } const long long inf = (long long) 8e18L; using T = long long; vector<T> dist(n, inf); priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > s; dist[0] = 0; s.emplace(0, 0); while (!s.empty()) { T exp = s.top().first; int u = s.top().second; s.pop(); if (exp != dist[u]) { continue; } if (u == target) { break; } for (auto [v, w] : g[u]) { if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; s.emplace(dist[v], v); } } } cout << (dist[target] >= inf ? -1 : dist[target]) << '\n'; return 0; }
#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...