Submission #248375

#TimeUsernameProblemLanguageResultExecution timeMemory
248375sahil_kJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
133 ms262148 KiB
#include <iostream> #include <vector> #include <set> using namespace std; int main () { int n, m; cin >> n >> m; int adj[n][n]; for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { adj[i][j] = 1e9; } } int bi, pi; int start, end; for (int i=0; i<m; i++) { cin >> bi >> pi; if (i == 0) start = bi; if (i == 1) end = bi; for (int j=1; j<n; j++) { if (bi-j*pi >= 0) adj[bi][bi-j*pi] = min(adj[bi][bi-j*pi], j); if (bi+j*pi < n) adj[bi][bi+j*pi] = min(adj[bi][bi+j*pi], j); } } set< pair<int, int> > ord; int dist[n]; bool vis[n]; for (int i=0; i<n; i++) { dist[i] = 1e9; vis[i] = false; } dist[start] = 0; ord.insert(make_pair(0, start)); while (ord.size() > 0) { pair<int, int> cur = *ord.begin(); ord.erase(ord.begin()); vis[cur.second] = true; for (int i=0; i<n; i++) { if (!vis[i] && cur.first+adj[cur.second][i] < dist[i]) { ord.erase(make_pair(dist[i], i)); dist[i] = cur.first+adj[cur.second][i]; ord.insert(make_pair(dist[i], i)); } } } if (dist[end] == 1e9) { cout << -1 << endl; } else { cout << dist[end] << endl; } }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:33:22: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ord.insert(make_pair(0, start));
             ~~~~~~~~~^~~~~~~~~~
skyscraper.cpp:46:14: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (dist[end] == 1e9) {
      ~~~~~~~~^
#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...