-
Notifications
You must be signed in to change notification settings - Fork 0
/
스타트링크.cc
45 lines (35 loc) · 905 Bytes
/
스타트링크.cc
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 <queue>
#include <cstring>
using namespace std;
int F, S, G;
int dx[2]; // 층수, 목적지, 출발점, 올라가는 수, 내려가는 수
int answer = 0;
int visited[1000002];
void bfs() {
queue<int> q;
q.push(S);
visited[S] = 0;
while(!q.empty()) {
int x = q.front();
q.pop();
for(int i=0; i < 2; i++) {
int nx = x + dx[i];
if (nx < 1 || nx > F) continue;
if (visited[nx] != -1) continue;
visited[nx] = visited[x] + 1;
q.push(nx);
}
}
if (visited[G] == -1) cout << "use the stairs";
else cout << visited[G];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(visited, -1, sizeof(visited));
cin >> F >> S >> G >> dx[0] >> dx[1];
dx[1] *= -1;
bfs();
return 0;
}