| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1357385 | Desh03 | Jakarta Skyscrapers (APIO15_skyscraper) | C++20 | 14 ms | 748 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;
set<int> alive;
for (int i = 0; i < n; i++) {
alive.insert(i);
}
while (true) {
int tt = 0;
vector<int> tr;
for (int j : alive) {
if (d[j] == inf) {
tt++;
continue;
}
bool ok = 1;
for (int k : v[j]) {
for (int t = j % k; t < n; t += k) {
if (d[t] > d[j] + abs(t - j) / k) {
d[t] = d[j] + abs(t - j) / k;
ok = 0;
}
}
}
if (ok) {
if (++cnt[j] > 3) {
tr.push_back(j);
v[j].clear();
}
++tt;
}
}
if (tt == alive.size()) break;
for (int j : tr) {
alive.erase(j);
}
}
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... | ||||
