Submission #199568

#TimeUsernameProblemLanguageResultExecution timeMemory
199568handlenameJakarta Skyscrapers (APIO15_skyscraper)C++17
22 / 100
1094 ms49872 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair int n,m,s,e; vector<pair<int,int> > adj[30001]; int dist[30001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; for (int i=0;i<m;i++){ int b,p; cin>>b>>p; if (i==0) s=b; if (i==1) e=b; int dis=1; for (int j=b+p;j<n;j+=p){ adj[b].pb(mp(j,dis)); dis++; } dis=1; for (int j=b-p;j>=0;j-=p){ adj[b].pb(mp(j,dis)); dis++; } } memset(dist,-1,sizeof(dist)); priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq; pq.push(mp(0,s)); while (!pq.empty()){ pair<int,int> cur=pq.top(); pq.pop(); if (dist[cur.second]!=-1) continue; dist[cur.second]=cur.first; for (auto i:adj[cur.second]){ pq.push(mp(cur.first+i.second,i.first)); } } cout<<dist[e]; }
#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...