# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106233 | Hideo | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1086 ms | 45200 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;
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pii pair < int, pi >
#define vii vector < pi >
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
int l[N], p[N], d[N];
int n, m, ans;
vii g[N];
priority_queue < pi > pq;
main(){
ans = INF;
cin >> n >> m;
for (int i = 1; i <= m; i++){
d[i] = INF;
scanf("%d%d", &l[i], &p[i]);
}
pq.push(mk(0, 1));
while (!pq.empty()){
int v = pq.top().sc, c = -pq.top().fr;
pq.pop();
if (c >= ans)
break;
if (c >= d[v])
continue;
if (v == 2){
ans = c;
continue;
}
if (d[v] == INF){
for (int j = 1; j <= m; j++)
if (v != j && l[v] % p[v] == l[j] % p[v])
g[v].pb(mk(j, abs(l[j] - l[v]) / p[v]));
}
d[v] = c;
for (pi to : g[v]){
if (d[to.fr] > d[v] + to.sc)
pq.push(mk(-d[v] - to.sc, to.fr));
}
}
if (ans == INF)
cout << -1;
else
cout << ans;
}
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... |