Submission #87780

#TimeUsernameProblemLanguageResultExecution timeMemory
87780KCSCJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
625 ms123452 KiB
#include <bits/stdc++.h> using namespace std; const int DIM = 30005; int ans[DIM]; pair<int, int> arr[DIM]; vector<int> lst[DIM]; bitset<DIM> oki[DIM], vis; struct str { int ps, pw, tm; }; deque<str> que; int main(void) { #ifdef HOME freopen("skyscraper.in", "r", stdin); freopen("skyscraper.out", "w", stdout); #endif int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> arr[i].first >> arr[i].second; lst[arr[i].first].push_back(i); ans[i] = 1000000000; } que.push_back({arr[0].first, arr[0].second, 0}); ans[0] = 0; oki[arr[0].first][arr[0].second] = true; while (que.size()) { int ps = que.front().ps, pw = que.front().pw, tm = que.front().tm; que.pop_front(); if (!vis[ps]) { vis[ps] = true; for (int x : lst[ps]) { ans[x] = min(ans[x], tm); if (!oki[arr[x].first][arr[x].second]) { oki[arr[x].first][arr[x].second] = true; que.push_front({arr[x].first, arr[x].second, tm}); } } } if (ps + pw < n and !oki[ps + pw][pw]) { oki[ps + pw][pw] = true; que.push_back({ps + pw, pw, tm + 1}); } if (ps - pw >= 0 and !oki[ps - pw][pw]) { oki[ps - pw][pw] = true; que.push_back({ps - pw, pw, tm + 1}); } } if (ans[1] == 1000000000) { ans[1] = -1; } cout << ans[1]; return 0; }
#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...