# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566180 | ac2hu | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 2 ms | 416 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n, m;cin >> n >> m;
vector<pair<int,int>> doge(m);
for(auto &[x,y] : doge)cin >> x >> y;
vector<vector<pair<int,int>>> adj(m);
for(int i = 0;i<m;i++){
for(int j = 0;j<m;j++){
if(i == j)continue;
int ab = abs(doge[i].first - doge[j].first);
if(ab%doge[i].second == 0){
adj[i].push_back({j, ab/doge[i].second});
}
}
}
vector<int> dist(n, 1e9);
dist[0] = 0;
priority_queue<pair<int,int>> pq;
pq.push({-dist[0], 0});
while(!pq.empty()){
auto [dd, x] = pq.top();
pq.pop();
dd = -dd;
if(dist[x] < dd)continue;
for(auto [e, w] : adj[x]){
if(dist[e] > dist[x] + w){
dist[e] = dist[x] + w;
pq.push({-dist[e], e});
}
}
}
if(dist[1] == 1e9)
cout << -1 << "\n";
else
cout << dist[1] << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |