| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1357360 | Desh03 | Jakarta Skyscrapers (APIO15_skyscraper) | C++20 | 1095 ms | 3740 KiB |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> v(n);
set<pair<int, int>> st;
int u, w;
for (int i = 0; i < m; i++) {
int b, p;
cin >> b >> p;
if (i == 0) u = b;
if (i == 1) w = b;
if (p >= n || st.find({b, p}) != st.end()) continue;
v[b].push_back(p);
st.insert({b, p});
}
vector<int> d(n, inf), cnt(n);
d[u] = 0;
while (true) {
auto nd = d;
int tt = 0;
for (int j = 0; j < n; j++) {
if (d[j] == inf || v[j].empty()) {
tt++;
continue;
}
bool ok = 1;
for (int k : v[j]) {
for (int t = j % k; t < n; t += k) {
if (nd[t] > d[j] + abs(t - j) / k) {
nd[t] = d[j] + abs(t - j) / k;
ok = 0;
}
}
}
if (ok) {
++cnt[j];
++tt;
}
if (cnt[j] > 10) {
v[j].clear();
}
}
d.swap(nd);
if (tt == n) break;
}
cout << (d[w] == inf ? -1 : d[w]) << '\n';
return 0;
}
| # | 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... | ||||
