Submission #132198

#TimeUsernameProblemLanguageResultExecution timeMemory
132198shafinalamJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
595 ms262148 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 3e4+5; typedef pair<int,int>pii; vector<pii>adj[mxn]; vector<pii>tmp; 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; scanf("%d%d", &b, &p); if(i==0) src = b; if(i==1) des = b; tmp.push_back(make_pair(b, p)); } sort(tmp.begin(), tmp.end()); tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end()); for(int i = 0; i < tmp.size(); i++) { int b = tmp[i].first; int p = tmp[i].second; int x = b+p, k = 1; 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++; } } 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:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < tmp.size(); i++)
                    ~~^~~~~~~~~~~~
skyscraper.cpp:38: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:44: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:71:32: warning: 'des' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ans = dijkstra(src, des);
                                ^
skyscraper.cpp:71: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...