Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- signed main()
- {
- int n;
- string s;
- int x = 0 , y = 0;
- cin >> n;
- cin >> s;
- map<pair<int , int> , bool> visited;
- visited[{0 , 0}] = true;
- for(int i = 0; i < n; i++){
- if(s[i] == 'L')
- x--;
- if(s[i] == 'R')
- x++;
- if(s[i] == 'D')
- y--;
- if(s[i] == 'U')
- y++;
- if(visited[{x , y}]){
- cout << "Yes" << endl;
- return 0;
- }
- visited[{x , y}] = true;
- }
- cout << "No" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement