# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34836 | simotion | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 0 ms | 2016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |