# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1077830 | dosts | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 30 ms | 4820 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.
//DOST SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC optimise("O3,unroll-loops")
using namespace std;
#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
int tx;
vector<int> dis(n, LLONG_MAX);
vector<set<int>> p(n);
priority_queue<pii> q;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
p[x].insert(y);
if (!i) {
dis[x] = 0;
q.push({0, x});
}
else if (i == 1) tx = x;
}
while (!q.empty()) {
auto [d, x] = q.top(); d = -d; q.pop();
if (d != dis[x]) continue;
for (auto j : p[x]) {
for (int i = x + j; i < n; i += j) {
if (!p[i].empty() && d + abs(i - x) / j < dis[i]) {
dis[i] = d + abs(i - x) / j;
q.push({-dis[i], i});
}
if (p[i].find(j) != p[i].end()) break;
}
for (int i = x - j; i >= 0; i -= j) {
if (!p[i].empty() && d + abs(i - x) / j < dis[i]) {
dis[i] = d + abs(i - x) / j;
q.push({-dis[i], i});
}
if (p[i].find(j) != p[i].end()) break;
}
}
}
cout << (dis[tx] == LLONG_MAX ? -1 : dis[tx]);
}
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... |