# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400776 | BERNARB01 | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 339 ms | 262148 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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, long long>>> g(n);
int target, start;
for (int i = 0; i < m; i++) {
int b, p;
cin >> b >> p;
if (i == 0) {
start = b;
}
if (i == 1) {
target = b;
}
for (int j = 0; j < n; j++) {
int d = abs(b - j);
if (d % p == 0) {
g[b].emplace_back(j, d / p);
}
}
}
const long long inf = (long long) 8e18L;
vector<long long> dist(n, inf);
priority_queue<pair<long long, int>> s;
dist[start] = 0;
s.emplace(0, start);
while (!s.empty()) {
long long exp = -s.top().first;
int u = s.top().second;
s.pop();
if (exp != dist[u]) {
continue;
}
for (auto [v, w] : g[u]) {
if (dist[u] + w < dist[v]) {
dist[v] = dist[u] + w;
s.emplace(-dist[v], v);
}
}
}
cout << (dist[target] >= inf ? -1 : dist[target]) << '\n';
return 0;
}
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... |