# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477295 | KienTran | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1089 ms | 788 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>
using namespace std;
const int O = 3e4 + 5;
const int inf = 1e9;
int n, m, b[O], d[O], p[O];
bool inq[O];
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++ i){
cin >> b[i] >> p[i];
}
for (int i = 1; i <= m; ++ i) d[i] = inf;
d[1] = 0;
priority_queue <int, vector <int>, greater <int>> q;
q.push(1); inq[1] = true;
while (q.size()){
int u = q.top();
q.pop();
inq[u] = false;
for (int v = 1; v <= m; ++ v){
if (v != u && d[v] > d[u] + abs(b[u] - b[v]) / p[u] && abs(b[u] - b[v]) % p[u] == 0){
d[v] = d[u] + abs(b[u] - b[v]) / p[u];
if (inq[v] == false){
q.push(v);
inq[v] = true;
}
}
}
}
if (d[2] >= inf) cout << -1;
else cout << d[2];
}
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... |