# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977499 | Amaarsaa | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1094 ms | 2192 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;
using ll = long long ;
ll D[30005];
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
ll t, n, m, ans, s, sum, x, y, r, p, i, j;
cin >> m >> n;
priority_queue < pair < ll, ll >, vector < pair < ll, ll >> , greater < pair < ll, ll >> > pq;
ll a[n + 2], b[n + 2];
for (i = 0; i < n; i ++) {
cin >> a[i] >> b[i];
D[i] = 1e18;
}
D[0] = 0;
pq.push({0, 0});
while(!pq.empty()) {
x = pq.top().first;
i = pq.top().second;
pq.pop();
if ( x != D[i]) continue;
if ( i == 1) {
cout << x << endl;
return 0;
}
for (j = 0; j < n; j ++) {
if ( (abs(a[j] - a[i])) % b[i] == 0) {
s = abs(a[j] - a[i]) / b[i];
if (D[j] > D[i] + s) {
D[j] = D[i] + s;
pq.push({D[j], j});
}
}
}
}
cout << -1 << endl;
}
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... |