Submission #455662

#TimeUsernameProblemLanguageResultExecution timeMemory
455662Hamed5001Jakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
5 ms1888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 3e4+10, 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() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); solve(); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:68:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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...