# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23564 | samir_droubi | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 373 ms | 112020 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;
int n,m;
const int mxn=(1e5)+5;
vector<pair<int,int> >gr[mxn];
set<int>a[mxn];
set<pair<int,int> >s;
int st,en;
int dis[mxn];
set<pair<int,int> >::iterator it;
set<int>::iterator itt;
void dijk()
{
for(int i=0;i<mxn;++i)dis[i]=(1e9);
dis[st]=0;
s.insert({0,st});
while(!s.empty())
{
it=s.begin();
int v=it->second;
int d=it->first;
s.erase(it);
for(int i=0;i<gr[v].size();++i)
{
int u=gr[v][i].first;
int w=gr[v][i].second;
if(d+w<dis[u])
{
dis[u]=d+w;
s.insert({d+w,u});
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;++i)
{
int b,p;
scanf("%d%d",&b,&p);
a[b].insert(p);
if(i==0)st=b;
if(i==1)en=b;
}
for(int i=0;i<n;++i)
{
itt=a[i].begin();
for(itt;itt!=a[i].end();++itt)
{
int p=*itt;
for(int j=1;i+(j*p)<n;++j)
{
int cur=i+(j*p);
gr[i].push_back({cur,j});
if(a[cur].count(p))break;
}
}
}
for(int i=n-1;i>=0;--i)
{
itt=a[i].begin();
for(itt;itt!=a[i].end();++itt)
{
int p=*itt;
for(int j=1;i-(j*p)>=0;++j)
{
int cur=i-(j*p);
gr[i].push_back({cur,j});
if(a[cur].count(p))break;
}
}
}
dijk();
if(dis[en]==(1e9))dis[en]=-1;
printf("%d\n",dis[en]);
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... |