Submission #132197

#TimeUsernameProblemLanguageResultExecution timeMemory
132197shafinalamJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
544 ms262148 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 3e4+5; typedef pair<int,int>pii; vector<pii>adj[mxn]; int dis[mxn]; int n, m; int dijkstra(int src, int des) { priority_queue<pii, vector<pii>, greater<pii> >pq; for(int i = 0; i < n; i++) dis[i] = 999999999; dis[src] = 0; pq.push(make_pair(0, src)); while(!pq.empty()) { pii cur = pq.top(); int u = cur.second; int cost = cur.first; pq.pop(); for(pii x : adj[u]) { int v = x.first; int w = x.second; if(dis[v]>w+cost) { dis[v] = w+cost; pq.push(make_pair(dis[v], v)); } } } return dis[des]; } int main() { scanf("%d%d", &n, &m); int src, des; for(int i = 0; i < m; i++) { int b, p, k = 1; scanf("%d%d", &b, &p); int x = b+p; while(x<n) { adj[b].push_back(make_pair(x, k)); x+=p; k++; } x = b-p, k = 1; while(x>=0) { adj[b].push_back(make_pair(x, k)); x-=p; k++; } if(i==0) src = b; if(i==1) des = b; } int ans = dijkstra(src, des); if(ans==999999999) cout << -1 << '\n'; else cout << ans << '\n'; return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &b, &p);
         ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:61:32: warning: 'des' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ans = dijkstra(src, des);
                                ^
skyscraper.cpp:61:32: 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...