fork(2) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool vis[1000001];
  4. int main()
  5. {
  6. // cout<<"z"<<endl;
  7. int f,s,g,u,d;
  8. cin>>f>>s>>g>>u>>d;
  9. queue<pair<int,int> > q;
  10. q.push(make_pair(s,0));
  11. pair<int,int> temp;
  12. int found=0;
  13. // cout<<"a"<<endl;
  14. while(!q.empty())
  15. {
  16. // cout<<"b"<<endl;
  17. temp=q.front();
  18. q.pop();
  19. vis[temp.first]=true;
  20. if(temp.first==g)
  21. {
  22. found=1;
  23. break;
  24. }
  25. if(temp.first+u<=f && vis[temp.first+u]==false)
  26. {
  27. q.push(make_pair(temp.first+u,temp.second+1));
  28. }
  29. if(temp.first-d>=1 && vis[temp.first-d]==false)
  30. {
  31. q.push(make_pair(temp.first-d,temp.second+1));
  32. }
  33. }
  34. if(found==1)
  35. cout<<temp.second<<endl;
  36. else
  37. cout<<"use the stairs"<<endl;
  38. return 0;
  39. }
Runtime error #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
Standard output is empty