# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839351 | popovicirobert | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 285 ms | 112532 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>
using namespace std;
constexpr int MAXN = 30'000;
constexpr int MAXP = 30'000;
bitset<MAXP + 1> visited[MAXN];
struct Node {
unsigned short b, p;
int dist;
};
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<unsigned short> b(m), p(m);
vector<vector<unsigned short>> P(n);
for (int i = 0; i < m; i++) {
cin >> b[i] >> p[i];
P[b[i]].push_back(p[i]);
}
deque<Node> Q;
Q.push_front({b[0], p[0], 0});
visited[b[0]][p[0]] = true;
while (Q.size()) {
auto curr = Q.front();
Q.pop_front();
auto Go = [&Q](int b, int p, int dist, bool front) {
if (!visited[b][p]) {
if (front) {
Q.push_front({b, p, dist});
} else {
Q.push_back({b, p, dist});
}
visited[b][p] = true;
}
};
if (curr.b == b[1]) {
cout << curr.dist << "\n";
return 0;
}
for (auto p : P[curr.b]) {
Go(curr.b, p, curr.dist, true);
}
if (curr.b >= curr.p) {
Go(curr.b - curr.p, curr.p, curr.dist + 1, false);
}
if (curr.b + curr.p < n) {
Go(curr.b + curr.p, curr.p, curr.dist + 1, false);
}
}
cout << -1 << "\n";
return 0;
}
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... |