# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
725073 | tigar | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1093 ms | 262144 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;
typedef long long ll;
ll b[50030], p[50030];
vector<ll>srapers[50030];
vector<pair<ll, ll> >graff[50030];
ll dist[50030];
bool check1[50030];
ll INF=LONG_LONG_MAX;
void dijkstra(ll cvor)
{
for(int i=0; i<50030; i++){check1[i]=false; dist[i]=INF;}
priority_queue<pair<ll, ll> >ord;
dist[cvor]=0;
ord.push({0, cvor});
while(!ord.empty())
{
int cv=ord.top().second;
ord.pop();
if(check1[cv])continue;
check1[cv]=true;
for(int j=0; j<graff[cv].size(); j++)
{
ll pp=graff[cv][j].first;
dist[pp]=min(dist[pp], dist[cv]+graff[cv][j].second);
if(!check1[pp])ord.push({-dist[pp], pp});
}
}
}
int main()
{
ll m, n;
cin>>n>>m;
for(int i=0; i<m; i++)
{
cin>>b[i]>>p[i];
srapers[b[i]].push_back(i);
}
for(int i=0; i<m; i++)
{
ll br=0;
while(b[i]-br*p[i]>=0 or b[i]+br*p[i]<n)
{
int j;
if(b[i]-br*p[i]>=0)
{
j=b[i]-br*p[i];
for(int l=0; l<srapers[j].size(); l++)
{
graff[i].push_back({srapers[j][l], br});
}
}
if(b[i]+br*p[i]<n)
{
j=b[i]+br*p[i];
for(int l=0; l<srapers[j].size(); l++)
{
graff[i].push_back({srapers[j][l], br});
}
}
br++;
}
}
dijkstra(0);
if(dist[1]==INF){cout<<-1; return 0;}
cout<<dist[1];
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... |