Advertisement
Guest User

Untitled

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