Submission #66652

#TimeUsernameProblemLanguageResultExecution timeMemory
66652tincamateiJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1090 ms64692 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 30000; vector<pair<int, int> > graph[MAX_N]; map<pair<int, int>, bool> doges; int dist[MAX_N]; bool inQueue[MAX_N]; int dijkstra(int n, int src, int dest) { int firstDist = 0, cons = 0; deque<deque<int> > pq(n); memset(dist, 0x3f3f3f3f, sizeof(dist)); dist[src] = 0; pq.front().push_back(src); while(cons <= n) { pq.push_back(deque<int>()); if(pq.front().empty()) ++cons; else cons = 0; for(auto nod: pq.front()) { if(firstDist == dist[nod]) { if(nod == dest) return firstDist; for(auto it: graph[nod]) if(firstDist + it.second < dist[it.first]) { dist[it.first] = firstDist + it.second; pq[it.second].push_back(it.first); } } } pq.pop_front(); ++firstDist; } return -1; } int main() { int n, m, b, p, src, dest; scanf("%d%d", &n, &m); for(int i = 0; i < m; ++i) { scanf("%d%d", &b, &p); if(i == 0) src = b; if(i == 1) dest = b; doges[make_pair(b, p)] = true; } for(auto it: doges) { pair<int, int> doge = it.first; if(it.second) { int poz = doge.first - doge.second, cost = 1; bool foundSimilar = false; while(poz >= 0 && !foundSimilar) { graph[doge.first].push_back(make_pair(poz, cost++)); if(doges[make_pair(poz, doge.second)]) foundSimilar = true; poz -= doge.second; } poz = doge.first + doge.second, cost = 1; foundSimilar = false; while(poz < n && !foundSimilar) { graph[doge.first].push_back(make_pair(poz, cost++)); if(doges[make_pair(poz, doge.second)]) foundSimilar = true; poz += doge.second; } } } printf("%d", dijkstra(n, src, dest)); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &b, &p);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:79:9: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
   printf("%d", dijkstra(n, src, dest));
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:79:9: warning: 'src' 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...