Submission #499521

#TimeUsernameProblemLanguageResultExecution timeMemory
499521StickfishJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
18 ms1612 KiB
#include <iostream> #include <bitset> #include <deque> #include <vector> using namespace std; const int MAXN = 2001; bitset<MAXN> used[MAXN]; bitset<MAXN> used_sky; vector<int> dog[MAXN]; signed main() { int n, m; cin >> n >> m; deque<pair<pair<int, int>, int>> q; int togo = 0; for (int i = 0; i < m; ++i) { int j, p; cin >> j >> p; dog[j].push_back(p); if (i == 0) { q.push_back({{j, p}, 0}); used[j][p] = 1; } else if (i == 1) { togo = j; } } while (q.size()) { auto [pr, d] = q.front(); auto [j, p] = pr; q.pop_front(); if (j == togo) { cout << d << endl; return 0; } if (!used_sky[j]) { used_sky[j] = 1; for (auto p0 : dog[j]) { if (!used[j][p0]) { used[j][p0] = 1; q.push_front({{j, p0}, d}); } } } if (j >= p && !used[j - p][p]) { used[j - p][p] = 1; q.push_back({{j - p, p}, d + 1}); } if (j + p < n && !used[j + p][p]) { used[j + p][p] = 1; q.push_back({{j + p, p}, d + 1}); } } cout << -1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...