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<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
struct wi{
vector<int> Q;
}*w;
bool odw[30000][30000];
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,m,x,y;
cin>>n>>m;
int gdzie0=0,gdzie1=0;
w=new wi[n+3];
for(int i=1;i<=m;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
if(i==1)
gdzie0=x;
if(i==2)
gdzie1=x;
}
queue<pair<int,pair<int,int> > > kolejka;
kolejka.push({gdzie0,{0,0}});
while(!kolejka.empty())
{
pair<int,pair<int,int> > para=kolejka.front();
kolejka.pop();
int x=para.first;
if(x==gdzie1)
{
cout<<para.second.first;
return 0;
}
int ile=para.second.first;
int jakim=para.second.second;
if(x-jakim>=0 && odw[x-jakim][jakim]==0)
{
odw[x-jakim][jakim]=1;
kolejka.push({x-jakim,{ile+1,jakim}});
}
if(x+jakim<n && odw[x+jakim][jakim]==0)
{
odw[x+jakim][jakim]=1;
kolejka.push({x+jakim,{ile+1,jakim}});
}
for(int i=0;i<w[x].Q.size();i++)
{
int pom=w[x].Q[i];
if(x-pom>=0 && odw[x-pom][pom]==0)
{
odw[x-pom][pom]=1;
kolejka.push({x-pom,{ile+1,pom}});
}
if(x+pom<n && odw[x+pom][pom]==0)
{
odw[x+pom][pom]=1;
kolejka.push({x+pom,{ile+1,pom}});
}
}
}
cout<<"-1";
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0;i<w[x].Q.size();i++)
| ~^~~~~~~~~~~~~~
# | 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... |