# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121286 | mmdrzada | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1042 ms | 1956 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 <iostream>
#include <vector>
using namespace std;
vector<int> g[30005];
int f[30005], da[30005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, h, k;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if (i == 1) h = x;
if (i == 2) k = x;
g[x].push_back(y);
}
for (int i = 0; i < n; i++) f[i] = 1e9;
f[h] = 0;
for (int jj = 0; jj < n; jj++) {
int p, mi = 1e9;
for (int i = 0; i < n; i++) {
if (da[i] == 0 && mi > f[i]) {
mi = f[i];
p = i;
}
}
if (p == k) break;
da[p] = 1;
for (int w : g[p]) {
int l = 0;
for (int j = p - w; j >= 0; j -= w) {
f[j] = min(f[j], f[p] + l + 1);
l++;
}
l = 0;
for (int j = p + w; j < n; j += w) {
f[j] = min(f[j], f[p] + l + 1);
l++;
}
}
}
if (f[k] == 1e9) cout << -1;
else cout << f[k];
}
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... |