제출 #248367

#제출 시각아이디문제언어결과실행 시간메모리
248367sahil_kJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
367 ms262148 KiB
#include <iostream> #include <vector> #include <set> using namespace std; int main () { int n, m; cin >> n >> m; vector< pair<int, int> > adj[n]; 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].push_back(make_pair(bi-j*pi, j)); if (bi+j*pi < n) adj[bi].push_back(make_pair(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 (auto i: adj[cur.second]) { if (!vis[i.first] && cur.first+i.second < dist[i.first]) { ord.erase(make_pair(dist[i.first], i.first)); dist[i.first] = cur.first+i.second; ord.insert(make_pair(dist[i.first], i.first)); } } } if (dist[end] == 1e9) { cout << -1 << endl; } else { cout << dist[end] << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:28:22: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ord.insert(make_pair(0, start));
             ~~~~~~~~~^~~~~~~~~~
skyscraper.cpp:41: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...