# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954782 | BbtT | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 440 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.
#include<bits/stdc++.h>
using namespace std;
struct edge{
int n,w;
};
bool operator<(edge a,edge b){
return a.w<b.w;
}
int main(){
int N,M;
cin>>N>>M;
vector<vector<edge>> edges(N);
for(int i=0;i<M;i++){
int b,p;
scanf("%d%d",&b,&p);
vector<edge> temp;
for(int j=b-p;j>=0;j-=p)temp.push_back((edge){j,(b-j)/p});
for(int j=b+p;j<N;j+=p)temp.push_back((edge){j,(j-b)/p});
edges.push_back(temp);
edges[b].push_back((edge){edges.size()-1,0});
}
bitset<30005> vis;
priority_queue<edge> pq;
vis[0]=1;
pq.push((edge){0,0});
while(!pq.empty()){
edge cur_edge=pq.top();
pq.pop();
vis[cur_edge.n]=1;
if(cur_edge.n==1){
cout<<cur_edge.w<<endl;
return 0;
}
for(auto togo: edges[cur_edge.n]){
if(vis[togo.n])continue;
pq.push((edge){togo.n,cur_edge.w+togo.w});
}
}
cout<<-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... |