Submission #34836

#TimeUsernameProblemLanguageResultExecution timeMemory
34836simotionJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
0 ms2016 KiB
#include <bits/stdc++.h> #define ll long long #define mp make_pair #define pi pair<int,int> #define fi first #define se second #define SIZ 31 #define INF 1e9 using namespace std; int n,m; int b[SIZ],p[SIZ]; int t1,t2; bool visited[SIZ]; int dist[SIZ]; int main() { scanf("%d %d",&n,&m); for(int i=0;i<m;i++) { scanf("%d %d",&b[i],&p[i]); dist[i]=INF; } dist[0]=0; priority_queue<pi,vector<pi >,greater<pi > > pq; pq.push(mp(0,0)); while(!pq.empty()&&!visited[1]) { auto now=pq.top(); pq.pop(); if(visited[now.se]) continue; visited[now.se]=true; int loc=b[now.se],jmp=p[now.se]; for(int i=0;i<m;i++) { if(loc!=b[i]&&abs(loc-b[i])%jmp==0) { int cand=now.fi+abs(loc-b[i])/jmp; pq.push(mp(cand,i)); dist[i]=min(dist[i],cand); } } } if(!visited[1]) printf("-1"); else printf("%d",dist[1]); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:16:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
                         ^
skyscraper.cpp:18:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&b[i],&p[i]);
                                   ^
#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...