이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int N,M,pos,S,buscar,b;
queue <pair<int,int> > varioinicio;
cin>>N>>M;
vector<pair<int,int> > doge(M);
vector<int> distancia(N,1e9);
for(int i=0;i<M;i++){
cin>>pos>>S;
if(i==0)b=pos;
if(i==1)buscar=pos;
doge[i]=make_pair(pos,S);
if(pos==b)varioinicio.push(doge[i]);
}
queue <pair<pair<int,int>,int> > q;
q.push(make_pair(doge[0],0));
while(!varioinicio.empty()){
q.push(make_pair(varioinicio.front(),0));
varioinicio.pop();
}
distancia[0]=0;
while(!q.empty()){
int p=q.front().first.first;
int mov=q.front().first.second;
int jump=q.front().second;
q.pop();
int po=p;
int mo=mov;
int jum=jump;
while(p){
if(distancia[p]>jump){
distancia[p]=jump;
//cout<<distancia[p]<<' '<<p<<' ';
for(int i=0;i<M;i++)if(doge[i].first==p&&p!=buscar)q.push(make_pair(doge[i],jump));
}
p-=mov;
jump++;
}
while(po<N){
if(distancia[po]>jum){
distancia[po]=jum;
//cout<<distancia[po]<<' '<<po<<' ';
for(int i=0;i<M;i++)if(doge[i].first==po&&po!=buscar)q.push(make_pair(doge[i],jum));
}
jum++;
po+=mo;
}
}
if(distancia[buscar]==1e9)cout<<-1;
else cout<<distancia[buscar];
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:54:20: warning: 'buscar' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | if(distancia[buscar]==1e9)cout<<-1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |