제출 #108296

#제출 시각아이디문제언어결과실행 시간메모리
108296maruiiJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
686 ms3620 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define ff first #define ss second priority_queue<pii, vector<pii>, greater<pii> > pq; int dst[30000]; vector<int> edge[30000]; int main(){ ios_base::sync_with_stdio(0), cin.tie(0); int N, M, st, ed; cin>>N>>M; for(int i=0; i<M; ++i){ int b,p; cin>>b>>p; edge[b].push_back(p); if(!i) st = b; else if(i==1) ed = b; } fill(dst, dst+N, 1e9); pq.emplace(0, st); dst[st] = 0; while(pq.size()){ auto x = pq.top(); pq.pop(); if(x.ff != dst[x.ss]) continue; for(auto p: edge[x.ss]){ for(int j=0; x.ss+p*j<N; ++j){ if(dst[x.ss+p*j] > x.ff + j){ dst[x.ss+p*j] = x.ff + j; pq.emplace(x.ff + j, x.ss+p*j); } } for(int j=1; x.ss-p*j>=0; ++j){ if(dst[x.ss-p*j] > x.ff + j){ dst[x.ss-p*j] = x.ff + j; pq.emplace(x.ff + j, x.ss-p*j); } } } } cout<<(dst[ed]==1e9?-1:dst[ed]); return 0; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:21:29: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pq.emplace(0, st); dst[st] = 0;
                     ~~~~~~~~^~~
skyscraper.cpp:41:15: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout<<(dst[ed]==1e9?-1:dst[ed]);
         ~~~~~~^
#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...