# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132196 | shafinalam | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 93 ms | 34124 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>
using namespace std;
const int mxn = 3e4+5;
typedef pair<int,int>pii;
vector<pii>adj[mxn];
int dis[mxn];
int n, m;
int dijkstra(int src, int des)
{
priority_queue<pii, vector<pii>, greater<pii> >pq;
for(int i = 1; i <= n; i++) dis[i] = 999999999;
dis[src] = 0;
pq.push(make_pair(0, src));
while(!pq.empty())
{
pii cur = pq.top();
int u = cur.second;
int cost = cur.first;
pq.pop();
for(pii x : adj[u])
{
int v = x.first;
int w = x.second;
if(dis[v]>w+cost)
{
dis[v] = w+cost;
pq.push(make_pair(dis[v], v));
}
}
}
return dis[des];
}
int main()
{
scanf("%d%d", &n, &m);
int src, des;
for(int i = 0; i < m; i++)
{
int b, p, k = 1;
scanf("%d%d", &b, &p);
int x = b+p;
while(x<n)
{
adj[b].push_back(make_pair(x, k));
x+=p;
k++;
}
x = b-p, k = 1;
while(x>=0)
{
adj[b].push_back(make_pair(x, k));
x-=p;
k++;
}
if(i==0) src = b;
if(i==1) des = b;
}
int ans = dijkstra(src, des);
if(ans==999999999) cout << -1 << '\n';
else cout << ans << '\n';
return 0;
}
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... |