# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700886 | nguyentunglam | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 336 ms | 225980 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>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 3e4 + 10, M = 1e9;
bool dd[M];
vector<int> lst[N];
int cnt;
bool mark[N];
bool id(int x, int y) {
int code = x * (3e4 + 1) + y;
if (dd[code]) return 1;
dd[code] = 1;
return 0;
}
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int n, m; cin >> n >> m;
pair<int, int> st, ed;
for(int i = 0; i < m; i++) {
int b, p; cin >> b >> p;
lst[b].push_back(p);
if (i == 0) st = make_pair(b, p);
if (i == 1) ed = make_pair(b, p);
}
deque<tuple<int, int, int> > dq;
id(st.fi, st.se);
dq.push_back({0, st.fi, st.se});
while (!dq.empty()) {
auto [cost, pos, jump] = dq.front(); dq.pop_front();
if (pos == ed.fi) return cout << cost, 0;
if (!mark[pos]) {
for(auto &j : lst[pos]) {
if (!id(pos, j)) dq.push_front({cost, pos, j});
}
mark[pos] = 1;
}
if (pos + jump < n) {
if (!id(pos + jump, jump)) dq.push_back({cost + 1, pos + jump, jump});
}
if (pos - jump >= 0) {
if (!id(pos - jump, jump)) dq.push_back({cost + 1, pos - jump, jump});
}
}
cout << -1;
}
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... |