제출 #400771

#제출 시각아이디문제언어결과실행 시간메모리
400771BERNARB01Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
247 ms262148 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, long long>>> g(n); int target, start; for (int i = 0; i < m; i++) { int b, p; cin >> b >> p; if (i == 0) { start = b; } if (i == 1) { target = b; } for (int j = b + p, w = 1; j < n; j += p, w++) { g[b].emplace_back(j, w); } for (int j = b - p, w = 1; j >= 0; j -= p, w++) { g[b].emplace_back(j, w); } } const long long inf = (long long) 8e18L; vector<long long> dist(n, inf); priority_queue<pair<long long, int>> s; dist[start] = 0; s.emplace(0, start); while (!s.empty()) { long long exp = -s.top().first; int u = s.top().second; s.pop(); if (exp != dist[u]) { continue; } if (u == target) { break; } for (auto [v, w] : g[u]) { if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; s.emplace(-dist[v], v); } } } cout << (dist[target] >= inf ? -1 : dist[target]) << '\n'; return 0; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:31:12: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |  dist[start] = 0;
      |            ^
skyscraper.cpp:40:3: warning: 'target' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |   if (u == target) {
      |   ^~
#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...