-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelevator.cpp
More file actions
executable file
·63 lines (56 loc) · 926 Bytes
/
elevator.cpp
File metadata and controls
executable file
·63 lines (56 loc) · 926 Bytes
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
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, n) for(int i=0; i<n; i++)
#define F first
#define S second
#define SIZE 1000000
int n, u, d;
bool vis[SIZE]={false};
int level[SIZE]={0};
void bfs(int r)
{
queue<int> q;
q.push(r);
vis[r]=true;
while(!q.empty())
{
int v=q.front();
q.pop();
// cout<<"for "<<v<<"\n";
// cout<<v-d<<"\n";
// cout<<v+u<<"\n";
if(v-d>=0)
{
if(!vis[v-d]){
q.push(v-d);
vis[v-d]=true;
level[v-d]=1+level[v];
}
}
if(v+u<n)
{
if(!vis[v+u]){
q.push(v+u);
vis[v+u]=true;
level[v+u]=1+level[v];
}
}
}
}
int32_t main(void)
{
int s, t;
cin>>n>>s>>t>>u>>d;
s--; t--;
bfs(s);
if(s==t) cout<<0<<"\n";
else if(vis[t]) cout<<level[t]<<"\n";
else cout<<"use the stairs\n";
//flp(i, n) cout<<vis[i]<<" ";
//cout<<"\n";
return 0;
}