Submission #1083205

#TimeUsernameProblemLanguageResultExecution timeMemory
1083205vjudge1Jakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
33 ms4568 KiB
#include<bits/stdc++.h> using namespace std; set<int>doge[30100]; int dist[30100],pos[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; for(int i=0;i<m;i++){ int b;cin>>pos[i]>>b; doge[pos[i]].insert(b); } dist[pos[0]]=0; pq.push({0,pos[0]}); 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[pos[1]]!=dist[30099]?dist[pos[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...