Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. long long n,yPos,xPos,i,k,;
  5. set < pair < long long , long long > > s;
  6. int main()
  7. {
  8. s.insert({0,0});
  9. int res= 0;
  10. xPos=0;
  11. yPos=0;
  12. cin >> n;
  13. for(i=1;i<=n;i++){
  14. cin >> k;
  15. if(k==1){
  16. xPos--;
  17. yPos++;
  18. }
  19. if(k==2){
  20. yPos++;
  21. }
  22. if(k==3){
  23. xPos++;
  24. yPos++;
  25. }
  26. if(k==4){
  27. xPos++;
  28. }
  29. if(k==5){
  30. xPos++;
  31. yPos--;
  32. }
  33. if(k==6){
  34. yPos--;
  35. }
  36. if(k==7){
  37. xPos--;
  38. yPos--;
  39. }
  40. if(k==8){
  41. xPos--;
  42. }
  43. if(s.count{xPos,yPos}==1){
  44. res = i;
  45. break;
  46. }
  47. }
  48. if(res!=0)cout<<res<<endl;
  49. else{
  50. cout<<"Ok"<<endl;
  51. cout<<abs(xPos)+abs(yPos)<<endl;
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement