# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955011 | BbtT | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 604 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 ed{
int n,w;
};
bool operator<(ed a,ed b){
return a.w<b.w;
}
int N,M,d[30005];
bitset<30005> vis;
vector<vector<ed>> edge;
int main(){
cin>>N>>M;
edge.resize(N);
for(int i=0;i<M;i++){
int b,p;
scanf("%d%d",&b,&p);
edge.push_back({});
edge[b].push_back((ed){edge.size()-1,0});
for(int j=b+p;j<N;j+=p){
edge.back().push_back((ed){j,(j-b)/p});
}
for(int j=b-p;j>=0;j-=p){
edge.back().push_back((ed){j,(b-j)/p});
}
}
priority_queue<ed> Q;
Q.push((ed){0,0});
while(!Q.empty()){
int cur=Q.top().n,wn=Q.top().w;
Q.pop();
vis[cur]=1;
for(auto togo:edge[cur]){
if(vis[togo.n])continue;
if(d[togo.n]>wn+togo.w||d[togo.n]==0){
d[togo.n]=wn+togo.w;
Q.push((ed){togo.n,d[togo.n]});
}
}
}cout<<d[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... |