forked from keysangyonthan/SPOJsolvent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathELEVTRBL.cpp
More file actions
56 lines (55 loc) · 1.02 KB
/
ELEVTRBL.cpp
File metadata and controls
56 lines (55 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//g++ 5.4.0
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/*
10 1 10 2 1
*/
ll s,g,u,d,f;
ll mark[1000001];
ll dist[1000001];
void compute()
{
//cout<<s<<" "<<f<<" "<<g<<u<<d;
ll current,next_up,next_down;
queue<ll>q;
q.push(s);
dist[s]=0;
mark[s]=1;
while(!q.empty())
{
current=q.front();
q.pop();
next_up=current+u;
next_down=current-d;
//cout<<next_up<<" "<<next_down<<" ";
while(next_up<=f && !mark[next_up])
{
mark[next_up]=1;
q.push(next_up);
dist[next_up]=dist[current]+1;
}
while(next_down>=1 && !mark[next_down])
{
mark[next_down]=1;
q.push(next_down);
dist[next_down]=dist[current]+1;
}
//cout<<q.size()<<endl;
}
return ;
}
int main()
{
cin>>f>>s>>g>>u>>d;
dist[g]=-1;
compute();
if(dist[g]==-1)
{
cout<<"use the stairs";
}
else
{
cout<<dist[g];
}
}