SHARE
TWEET

Untitled

a guest Jul 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <queue>
  2. #include <cstring>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const char buf[20] = "use the stairs";
  8. int dist[1000001];
  9.  
  10. int dx[2] = { 1, -1 };
  11.  
  12. int main(void) {
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(nullptr);
  15.  
  16.     int F, S, G, U, D;
  17.     cin >> F >> S >> G >> U >> D;
  18.  
  19.     memset(dist, -1, sizeof(dist));
  20.     queue<int> q;
  21.     q.push(S);
  22.     dist[S] = 0;
  23.  
  24.     dx[0] = U * dx[0];
  25.     dx[1] = D * dx[1];
  26.  
  27.     while (!q.empty()) {
  28.         int x = q.front();
  29.         q.pop();
  30.  
  31.         for (int i = 0; i < 2; i++) {
  32.             int tx = x + dx[i];
  33.             if (tx < 1 || tx > F || dist[tx] != -1) continue;
  34.             dist[tx] = dist[x] + 1;
  35.             q.push(tx);
  36.         }
  37.     }
  38.  
  39.     if (dist[G] == -1) {
  40.         cout << buf << '\n';
  41.     }
  42.     else {
  43.         cout << dist[G] << '\n';
  44.     }
  45.  
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top