Submission #320118

#TimeUsernameProblemLanguageResultExecution timeMemory
320118NicolaAbusaad2014Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1094 ms17088 KiB
/** * 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]; pq.pop(); 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)); } } } } if(vis[1]==-1e9){ cout<<-1<<endl; } else{ cout<<-vis[1]<<endl; } } return 0; }
#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...