제출 #931636

#제출 시각아이디문제언어결과실행 시간메모리
931636dnialhJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1067 ms56516 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<bool> 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.front(); if (loc == goal){ cout << d << '\n'; exit (0); } st.pop_front(); 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; }

컴파일 시 표준 에러 (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...