# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146036 | str0ct | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1066 ms | 2696 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;
using pii=pair <int,int>;
int vis[30303];
int N,M;
pair <int,int> ipt[30303];
vector <int> V[30303];
priority_queue<pii,vector<pii>,greater<pii> > pq;
void dijkstra(){
pq.push({0,ipt[0].first});
vis[ipt[0].first]=0;
while(!pq.empty()){
int a=pq.top().first,b=pq.top().second;
pq.pop();
if(a<=vis[b]){
for(auto i:V[b]){
int fl1=0,fl2=0;
for(int k=1;;k++){
if(fl1&&fl2)break;
if(k*i+b<N&&!fl1){if(vis[b+i*k]>a+k){
pq.push({a+k,b+i*k});
vis[b+i*k]=a+k;
if(binary_search(V[b+i*k].begin(),V[b+i*k].end(),i))fl1=1;
}}
else fl1=1;
if(b-k*i>=0&&!fl2){if(vis[b-i*k]>a+k){
pq.push({a+k,b-i*k});
vis[b-i*k]=a+k;
auto it=lower_bound(V[b-i*k].begin(),V[b-i*k].end(),i);
if(it!=V[b-i*k].end()&&*it==i)fl2=1;
}}
else fl2=1;
}
}
}
}
}
int main(){
fill(vis,vis+30303,101010);
scanf("%d%d",&N,&M);
for(int i=0;i<M;i++){
scanf("%d%d",&ipt[i].first,&ipt[i].second);
V[ipt[i].first].push_back(ipt[i].second);
}
for(int i=0;i<30003;i++){
sort(V[i].begin(),V[i].end());
V[i].erase(unique(V[i].begin(),V[i].end()),V[i].end());
}
dijkstra();
if(vis[ipt[1].first]!=101010)printf("%d",vis[ipt[1].first]);
else puts("-1");
}
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... |