Submission #455654

#TimeUsernameProblemLanguageResultExecution timeMemory
455654Hamed5001Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
401 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 3e4, OO = 0x3f3f3f3f; int N, M; vector<int> doges[mxN]; vector<pair<int, int>> adj[mxN]; int dijkstra(int st, int en) { vector<int> dist(mxN, OO); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, st}); while(pq.size()) { auto node = pq.top(); pq.pop(); if (node.first > dist[node.second]) continue; dist[node.second] = node.first; if (node.second == en) return node.first; for (auto it : adj[node.second]) { if (dist[it.second] > node.first + it.first) { dist[it.second] = node.first + it.first; pq.push({dist[it.second], it.second}); } } } return -1; } void solve() { cin >> N >> M; int stB, enB; for (int i = 0; i < M; i++) { int B, P; cin >> B >> P; if (!i) stB = B; if (!(i-1)) enB = B; doges[B].push_back(P); } for (int i = 0; i < N; i++) { for (auto doge : doges[i]) { for (int to = i + doge, j = 1; to < N; to += doge, j++){ adj[i].push_back({j, to}); if (count(doges[to].begin(), doges[to].end(), doge)) break; } for (int to = i - doge, j = 1; to >= 0; to -= doge, j++){ adj[i].push_back({j, to}); if (count(doges[to].begin(), doges[to].end(), doge)) break; } } } cout << dijkstra(stB, enB); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:62:27: warning: 'enB' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  cout << dijkstra(stB, enB);
      |                           ^
skyscraper.cpp:62:27: warning: 'stB' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...