# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699246 | nguyentunglam | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1079 ms | 34392 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 = 8e6 + 10;
map<pair<int, int>, int> dd;
vector<int> lst[N];
int d[M];
int cnt;
bool mark[N];
int id(int x, int y) {
if (!dd[{x, y}]) dd[{x, y}] = ++cnt;
return dd[{x, y}];
}
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<pair<int, int> > dq;
d[id(st.fi, st.se)] = 1; dq.push_back(st);
while (!dq.empty()) {
auto [pos, jump] = dq.front(); dq.pop_front();
int cur = id(pos, jump);
if (!mark[pos]) {
for(auto &j : lst[pos]) {
int code = id(pos, j);
if (!d[code]) d[code] = d[cur], dq.push_front({pos, j});
}
mark[pos] = 1;
}
if (pos + jump < n) {
int code = id(pos + jump, jump);
if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos + jump, jump});
}
if (pos - jump >= 0) {
int code = id(pos - jump, jump);
if (!d[code]) d[code] = d[cur] + 1, dq.push_back({pos - jump, jump});
}
}
cout << d[id(ed.fi, ed.se)] - 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... |