#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define X first
#define Y second
int board[1000001];
queue<int> q;
vector<int> dx;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int f,g,s,u,d;
int flag=0;
cin >> f >> s >> g >> u >> d;
if(s==g) {
cout << 0;
return 0;
}
dx.push_back(u);
dx.push_back(d);
fill(board,board+1000001,-1);
q.push(s);
board[s]=0;
while(!q.empty()) {
int cur=q.front();q.pop();
for(int i=0; i<2; i++) {
if(i==0) {
int nx=cur+dx[i];
if(nx>f) continue;
if(board[nx]!=-1) continue;
if(nx==g) {
cout << board[cur]+1;
flag=1;
return 0;
}
q.push(nx);
board[nx]=board[cur]+1;
} else {
int nx=cur-dx[i];
if(nx<1) continue;
if(board[nx]!=-1) continue;
if(nx==g) {
cout << board[cur]+1;
flag=1;
return 0;
}
q.push(nx);
board[nx]=board[cur]+1;
}
}
}
if(flag==0) {
cout << "use the stairs";
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: