This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Prof.Nicola
**/
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,m;
cin>>n>>m;
long long skyscraper[m],jumps[m];
vector<long long>vis(m,-1e9);
for(long i=0;i<m;i++){
cin>>skyscraper[i]>>jumps[i];
}
if(skyscraper[0]==skyscraper[1]){
cout<<0<<endl;
}
else{
priority_queue<pair<long long,long> >pq;
pq.push(make_pair(0,0));
long long cost,doge,pos,x;
while(!pq.empty()){
cost=pq.top().first;
doge=pq.top().second;
pos=skyscraper[doge];
if(cost>vis[doge]){
vis[doge]=cost;
for(long i=0;i<m;i++){
x=abs(skyscraper[i]-pos);
if(cost-(x/jumps[doge])>vis[i]&&x%jumps[doge]==0){
pq.push(make_pair(cost-(x/jumps[doge]),i));
}
}
}
pq.pop();
}
if(vis[1]==0){
cout<<-1<<endl;
}
else{
cout<<-vis[1]<<endl;
}
}
return 0;
}
# | 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... |