Submission #443780

#TimeUsernameProblemLanguageResultExecution timeMemory
443780impriJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms752 KiB
#include<bits/stdc++.h> using namespace std; int main(void){ int n,m; int arr[30001][2]; cin >> n >> m; for(int i=0;i<m;i++) cin >> arr[i][0] >> arr[i][1]; long long dist[30001]; dist[0]=0; for(int i=1;i<m;i++) dist[i]=10e15; priority_queue<pair<long long,int> >q; q.push({0,0}); while(!q.empty()){ int cur=q.top().second; long long curdist=-q.top().first; q.pop(); for(int i=0;i<m;i++){ if(abs(arr[cur][0]-arr[i][0])%arr[cur][1]!=0){ continue; } int nxtdist=abs(arr[cur][0]-arr[i][0])/arr[cur][1]; if(curdist+nxtdist<dist[i]){ dist[i]=curdist+nxtdist; q.push({-dist[i],i}); } } } if(dist[1]>10e12)cout << -1; cout << dist[1]; }
#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...