willy108

OMI-2017-Esperanza

Aug 30th, 2021
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <utility>
  4. #define pii pair<int, int>
  5. using namespace std;
  6. const int MX = 1e6 +10;
  7. char str[MX];
  8. int main() {
  9.   std::cin.tie(nullptr);
  10.   std::ios_base::sync_with_stdio(false);
  11.   int n; cin >> n >> str;
  12.   int x = 0, y = 0, ans = 0;
  13.   set<pii> vis;
  14.   for(int i = 0; i<=n; i++){
  15.     if(vis.count(make_pair(x, y))){ ans = 1; break;}
  16.     if(i == n) break;
  17.     vis.insert(make_pair(x, y));
  18.     if(str[i] == 'L') x--;
  19.     else if(str[i] == 'R') x++;
  20.     else if(str[i] == 'U') y++;
  21.     else y--;
  22.  
  23.   }
  24.   // TODO: fixme.
  25.   (ans && cout << "N\n") || cout << "S\n";
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment