Submission #931630

#TimeUsernameProblemLanguageResultExecution timeMemory
931630dnialhJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
1 ms600 KiB
#define set unordered_set #include <iostream> #include <vector> #include <set> #include <array> #include <tuple> #include <deque> using namespace std; typedef long long ll; int main() {ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> adj(n); vector<int> sta; vector<int> power; for (int i = 0; i < m; ++i) { int bi, pi; cin >> bi >> pi; adj[bi].push_back(i); sta.push_back(bi); power.push_back(pi); } int goal = sta[1]; vector<int> seen(n, 0); set<ll> par; int amt = 0; deque<tuple<int, int, int>> st; st.emplace_back(sta[0], 0, 0); while (!st.empty()) { auto [loc, p, d] = st.back(); if (loc == goal){ cout << d << '\n'; exit (0); } st.pop_back(); if (!seen[loc]) { seen[loc] = 1; for (int u : adj[loc]) { long long ind = (1LL * loc) << 32LL | (power[u]); //if (par.find(ind) == par.end()) { par.insert(ind); st.emplace_front(loc, power[u], d); //} } } ll u = loc + p; if (0 <= u && u < n) { long long ind = (u << 32LL) | p; if (par.find(ind) == par.end()) { par.insert(ind); st.push_back({u, p, d + 1}); } } u = loc - p; if (0 <= u && u < n) { long long ind = (u << 32LL) | p; if (par.find(ind) == par.end()) { par.insert(ind); st.push_back({u, p, d + 1}); } } } cout << -1 << '\n'; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:33:9: warning: unused variable 'amt' [-Wunused-variable]
   33 |     int amt = 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...