# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81829 | antimirage | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1062 ms | 12204 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>
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
using namespace std;
const int N = 3e4 + 5;
int n, m, en, pos, p, d[N], st;
set <int> vec[N];
priority_queue < pair <int, int> > q;
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &pos, &p);
vec[pos].insert(p);
if (i == 1)
st = pos;
if (i == 2)
en = pos;
}
memset(d, 0x3f3f3f3f, sizeof(d));
d[st] = 0;
q.push( mk( 0, st ) );
while (!q.empty())
{
int v = q.top().sc, len = -q.top().fr;
q.pop();
if (d[v] < len) continue;
for (auto to : vec[v])
{
for (int i = v % to; i < n; i += to)
{
if (d[i] > d[v] + abs(v - i) / to)
{
d[i] = d[v] + abs(v - i) / to;
q.push( mk( -d[i], i ) );
}
}
}
}
if (d[en] > 1e9)
d[en] = -1;
cout << d[en] << 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... |