Submission #695108

#TimeUsernameProblemLanguageResultExecution timeMemory
695108Ahmed_SolymanJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
2 ms1876 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]); if(b[i]==b[0]){ int u=b[i]; for(int j=b[i]-p[i];j>=0;j-=p[i]){ adj[u].push_back(j); u=j; } u=b[i]; for(int j=b[i]+p[i];j<n;j+=p[i]){ adj[u].push_back(j); u=j; } } } 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); vis[b[0]]=1; 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?dist[b[1]]:-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...