Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 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. cin>>n;
  8. for (k=1; k<=n; k++)
  9. {
  10. cin>>t;
  11. if (t==1) {
  12. x--;
  13. y++;
  14. }
  15. if (t==2) {
  16. y++;
  17. }
  18. if (t==3) {
  19. x++;
  20. y++;
  21. }
  22. if (t==4) {
  23. x++;
  24. }
  25. if (t==5) {
  26. x++;
  27. y--;
  28. }
  29. if (t==6) {
  30. y--;
  31. }
  32. if (t==7) {
  33. y--;
  34. x--;
  35. }
  36. if (t==8) {
  37. x--;
  38. }
  39. if (s.count({x,y})) res=k;
  40. s.insert({x,y});
  41.  
  42. }
  43. if (res!=0) cout<<res<<"\n";
  44. else cout<<abs(abs(x)-abs(y))<<"\n";
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement