# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132198 | shafinalam | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 595 ms | 262148 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];
vector<pii>tmp;
int dis[mxn];
int n, m;
int dijkstra(int src, int des)
{
priority_queue<pii, vector<pii>, greater<pii> >pq;
for(int i = 0; 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;
scanf("%d%d", &b, &p);
if(i==0) src = b;
if(i==1) des = b;
tmp.push_back(make_pair(b, p));
}
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
for(int i = 0; i < tmp.size(); i++)
{
int b = tmp[i].first;
int p = tmp[i].second;
int x = b+p, k = 1;
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++;
}
}
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... |