Submission #695112

#TimeUsernameProblemLanguageResultExecution timeMemory
695112Ahmed_SolymanJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
2 ms1896 KiB
#include<bits/stdc++.h> using namespace std; vector<int>adj[30000],g[30000],b(30000),p(30000); int main(){ int n,m;cin>>n>>m; for(int i=0;i<m;i++){ cin>>b[i]>>p[i]; g[b[i]].push_back(p[i]); } priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q; q.push({0,b[0]}); vector<int>dist(n+5,1e9); dist[b[0]]=0; vector<bool>vis(n+5); map<pair<int,int>,bool>v; while(q.size()){ pair<int,int>x=q.top(); q.pop(); dist[x.second]=min(dist[x.second],x.first); if(!vis[x.second]){ vis[x.second]=1; for(auto i:g[x.second]){ int s=x.second; int u=x.second+i; while(u<n)adj[s].push_back(u),s=u,u+=i; s=x.second; u=x.second-i; while(u>=0)adj[s].push_back(u),s=u,u-=i; } } for(auto i:adj[x.second]){ if(!v[{x.second,i}]){ v[{x.second,i}]=1; q.push({x.first+1,i}); } } } cout<<(dist[b[1]]==1e9?-1:dist[b[1]])<<endl; }
#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...