forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevatortrouble.cpp
45 lines (37 loc) · 915 Bytes
/
elevatortrouble.cpp
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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
ll inf = (ll(1) << 62);
int main() {
ll floors;
cin >> floors;
ll start, goal;
cin >> start >> goal;
start--;
goal--;
ll up, down;
cin >> up >> down;
vector<ll> visited(floors, inf);
visited[start] = 0;
queue<ll> q;
q.push(start);
while(!q.empty()) {
ll here = q.front();
q.pop();
if(here+up < floors && visited[here] + 1 < visited[here+up]) {
visited[here+up] = visited[here]+1;
q.push(here+up);
}
if(here-down >= 0 && visited[here] + 1 < visited[here-down]) {
visited[here-down] = visited[here]+1;
q.push(here-down);
}
}
if(visited[goal] == inf) {
cout << "use the stairs" << endl;
return 0;
}
cout << visited[goal] << endl;
}