Advertisement
LEGEND2004

LRUD Instructions 2

Aug 10th, 2023
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. signed main()
  7. {
  8.     int n;
  9.     string s;
  10.     int x = 0 , y = 0;
  11.     cin >> n;
  12.     cin >> s;
  13.    
  14.     map<pair<int , int> , bool> visited;
  15.     visited[{0 , 0}] = true;
  16.     for(int i = 0; i < n; i++){
  17.         if(s[i] == 'L')
  18.             x--;
  19.         if(s[i] == 'R')
  20.             x++;
  21.         if(s[i] == 'D')
  22.             y--;
  23.         if(s[i] == 'U')
  24.             y++;
  25.         if(visited[{x , y}]){
  26.             cout << "Yes" << endl;
  27.             return 0;
  28.         }
  29.         visited[{x , y}] = true;
  30.     }
  31.     cout << "No" << endl;
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement