제출 #705168

#제출 시각아이디문제언어결과실행 시간메모리
705168bebraJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
2 ms1832 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define dbg(x) cerr << #x << ": " << x << endl; const int MAX_N = 30000 + 5; const ll INF = 1e9; set<int> jumps[MAX_N]; ll dist[MAX_N]; bool used[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int s, t; for (int i = 0; i < m; ++i) { int v, k; cin >> v >> k; if (i == 0) s = v; if (i == 1) t = v; // for a jump let's save every vertex that includes it jumps[v].insert(k); } for (int v = 0; v < n; ++v) { set<int> erased; for (auto k : jumps[v]) { if (erased.find(k) != erased.end()) continue; for (int d = k * 2; d < n; d += k) { erased.insert(d); } } for (auto k : erased) { jumps[v].erase(k); } } fill_n(dist, n, INF); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.emplace(0, s); while (!pq.empty()) { auto [curr_dist, v] = pq.top(); pq.pop(); if (used[v]) continue; used[v] = true; dist[v] = curr_dist; if (v == t) break; if (dist[v] == INF) break; for (auto k : jumps[v]) { for (int u = v + k; u < n; u += k) { int w = (u - v) / k; if (used[u] || dist[v] + w >= dist[u]) continue; dist[u] = dist[v] + w; pq.emplace(dist[u], u); } for (int u = v - k; u >= 0; u -= k) { int w = (v - u) / k; if (used[u] || dist[v] + w >= dist[u]) continue; dist[u] = dist[v] + w; pq.emplace(dist[u], u); } } } if (!used[t]) { cout << "-1\n"; } else { cout << dist[t] << '\n'; } return 0; } /* 5 3 0 2 1 1 4 1 */

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:9: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         if (v == t) break;
      |         ^~
#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...