제출 #486498

#제출 시각아이디문제언어결과실행 시간메모리
486498fun_dayJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms276 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n , m; cin >> n >> m; vector<vector<pair<int,int>>> adj(n); for(int i = 0 ; i < m ; i++){ int a , b; cin >> a >> b; for(int j = a + b , cnt = 1 ; j < n ; j += b , cnt++){ adj[a].emplace_back(j , cnt); } for(int j = a - b , cnt = 1 ; j >= 0 ; j -= b , cnt++){ adj[a].emplace_back(j , cnt); } } priority_queue<pair<int,int> , vector<pair<int,int>> , greater<pair<int,int>>> pq; pq.emplace(0 , 0); vector<int> dist(n + 1 , (int)1e9); dist[0] = 0; while(!pq.empty()){ auto f = pq.top(); pq.pop(); if(f.first != dist[f.second]) continue; for(auto x : adj[f.second]){ int node = x.first; int cost = x.second; if(dist[node] > f.first + cost){ dist[node] = f.first + cost; pq.emplace(dist[node] , node); } } } if(dist[1] == (int)1e9) cout << -1 << '\n'; else cout << dist[1] << '\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...