Created
July 10, 2019 00:45
-
-
Save surinoel/6377b04d1ab38bb242fc81f5c73b886d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <queue> | |
#include <cstring> | |
#include <iostream> | |
using namespace std; | |
const char buf[20] = "use the stairs"; | |
int dist[1000001]; | |
int dx[2] = { 1, -1 }; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int F, S, G, U, D; | |
cin >> F >> S >> G >> U >> D; | |
memset(dist, -1, sizeof(dist)); | |
queue<int> q; | |
q.push(S); | |
dist[S] = 0; | |
dx[0] = U * dx[0]; | |
dx[1] = D * dx[1]; | |
while (!q.empty()) { | |
int x = q.front(); | |
q.pop(); | |
for (int i = 0; i < 2; i++) { | |
int tx = x + dx[i]; | |
if (tx < 1 || tx > F || dist[tx] != -1) continue; | |
dist[tx] = dist[x] + 1; | |
q.push(tx); | |
} | |
} | |
if (dist[G] == -1) { | |
cout << buf << '\n'; | |
} | |
else { | |
cout << dist[G] << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment