# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260787 | T0p_ | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 702 ms | 6004 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;
struct DJK
{
int node;
long long weight;
bool operator < (const DJK & o) const
{
return weight > o.weight;
}
};
vector<int> B[30003];
long long dis[30003];
bool visit[30003];
priority_queue<DJK> djk;
int main()
{
int n, m, s, e;
scanf(" %d %d",&n,&m);
for(int i=1, b, p ; i<=m ; i++)
{
scanf(" %d %d",&b,&p);
b++;
B[b].push_back(p);
if(i == 1) s = b;
if(i == 2) e = b;
}
for(int i=1 ; i<=n ; i++)
dis[i] = 1e15;
dis[s] = 0;
djk.push({s, 0});
while(!djk.empty())
{
int nown = djk.top().node;
long long noww = djk.top().weight;
djk.pop();
if(visit[nown]) continue ;
visit[nown] = true;
if(nown == e)
{
printf("%lld\n",noww);
return 0;
}
for(auto x : B[nown])
{
//left
for(int i=1 ; nown - x*i >= 1 ; i++)
if(dis[nown - x*i] > dis[nown] + i)
{
dis[nown - x*i] = dis[nown]+i;
djk.push({nown - x*i, dis[nown - x*i]});
}
//right
for(int i=1 ; nown + x*i <= n ; i++)
if(dis[nown + x*i] > dis[nown] + i)
{
dis[nown + x*i] = dis[nown]+i;
djk.push({nown + x*i, dis[nown + x*i]});
}
}
}
printf("-1\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... |