# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122436 | IOrtroiii | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 160 ms | 75984 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 N = 30030;
const int MG = 200;
const int inf = 1e9;
int d[N];
int b[N], p[N];
bool was[N][MG];
bool useless[N];
vector<pair<int, int>> g[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%d %d", b + i, p + i);
if (p[i] < MG) {
if (was[b[i]][p[i]]) {
useless[i] = true;
} else {
was[b[i]][p[i]] = true;
}
}
}
for (int i = 0; i < m; ++i) {
if (useless[i]) continue;
for (int j = 1; ; ++j) {
int v = b[i] - j * p[i];
if (v < 0) break;
g[b[i]].emplace_back(v, j);
if (p[i] < MG && was[v][p[i]]) {
break;
}
}
for (int j = 1; ; ++j) {
int v = b[i] + j * p[i];
if (v >= n) break;
g[b[i]].emplace_back(v, j);
if (p[i] < MG && was[v][p[i]]) {
break;
}
}
}
for (int i = 0; i < n; ++i) {
d[i] = inf;
}
priority_queue<pair<int, int>> q;
d[b[0]] = 0;
q.emplace(0, b[0]);
while (!q.empty()) {
int du, u;
tie(du, u) = q.top();
q.pop();
du = -du;
if (d[u] != du) {
continue;
}
for (auto e : g[u]) {
int v, w;
tie(v, w) = e;
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
q.emplace(-d[v], v);
}
}
}
printf("%d\n", (d[b[1]] == inf ? -1 : d[b[1]]));
}
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... |