# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320122 | NicolaAbusaad2014 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 655 ms | 262148 KiB |
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,z;
cin>>n>>m;
long long skyscraper[m],jumps[m];
vector<long long>doges[n];
vector<long long>vis(m,-1e9);
for(long i=0;i<m;i++){
cin>>skyscraper[i]>>jumps[i];
doges[skyscraper[i]].push_back(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;
z=pos%jumps[doge];
for(long i=z;i<n;i+=jumps[doge]){
x=abs(i-pos);
x/=jumps[doge];
for(long j=0;j<doges[i].size();j++){
if(cost-x>vis[doges[i][j]]){
pq.push(make_pair(cost-x,doges[i][j]));
}
}
}
}
}
if(vis[1]==-1e9){
cout<<-1<<endl;
}
else{
cout<<-vis[1]<<endl;
}
}
return 0;
}
Compilation message (stderr)
# | 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... |