Submission #1083202

#TimeUsernameProblemLanguageResultExecution timeMemory
1083202vjudge1Jakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms2136 KiB
#include<bits/stdc++.h> using namespace std; set<int>doge[30100]; int dist[30100]; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>>pq; int main(){ memset(dist,9,sizeof dist); int n,m; cin>>n>>m; int a,b;cin>>a>>b; doge[a].insert(b); dist[a]=0; pq.push({0,a}); for(int i=1;i<m;i++){ cin>>a>>b; doge[a].insert(b); } while(pq.size()){ auto[a,b]=pq.top(); pq.pop(); if(dist[b]!=a)continue; for(auto d:doge[b]){ for(int i=b-d;i>=0;i-=d){ int D=a+(b-i)/d; if(dist[i]>D&&doge[i].size()) pq.push({dist[i]=D,i}); if(doge[i].count(d)) break; } for(int i=b+d;i<n;i+=d){ int D=a+(i-b)/d; if(dist[i]>D&&doge[i].size()) pq.push({dist[i]=D,i}); if(doge[i].count(d)) break; } } } cout<<(dist[1]!=dist[30099]?dist[1]:-1); }
#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...