Advertisement
habiba3azb

Untitled

Feb 26th, 2023
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. /*     اللهم لا سهل الا ما جعلته سهلا وانت تجعل الحزن ان شأت سهلا                           */
  2. #include <bits/stdc++.h>
  3. #include <iomanip>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/tree_policy.hpp>
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. template <class T>
  9. using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
  10. template <typename T = int>
  11. ostream &operator<<(ostream &out, const vector<T> &v)
  12. {
  13.     for (const T &x : v)
  14.         out << x << ' ';
  15.     return out;
  16. }
  17. template <typename T = int>
  18. istream &operator>>(istream &in, vector<T> &v)
  19. {
  20.     for (auto &x : v)
  21.         in >> x;
  22.     return in;
  23. }
  24. using namespace __gnu_pbds;
  25. #define getline(s) getline(cin >> ws, s)
  26. #define ll long long
  27. #define sz(s) (int)(s.size())
  28. const int M = 2 * 1e5 + 5;
  29. #define HABIBA                        \
  30.     ios_base::sync_with_stdio(false); \
  31.     cin.tie(0);                       \
  32.     cout.tie(0);
  33. #define PI 3.14159
  34. #define pi 3.141592653589793
  35. #define ull unsigned long long
  36. #define all(s) s.begin(), s.end()
  37. #define fix(x) setprecision(x) << fixed
  38. #define PB push_back
  39. #define Mod 1'000'000'007
  40. #define to_binary(bin) stoll(bin, nullptr, 10)
  41. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  42. #define cin(v)        \
  43.     for (auto &i : v) \
  44.     cin >> i
  45. #define cout(v)       \
  46.     for (auto &i : v) \
  47.         cout << i << " ";
  48. #define Ndigits(n) ((int)log10(n) + 1)
  49. #define unq(VEC)    \
  50.     sort(all(VEC)); \
  51.     VEC.resize(unique(all(VEC)) - VEC.begin());
  52. using namespace std;
  53. #define Num_of_Digits(n) ((int)log10(n) + 1)
  54. #define cin_2d(vec, n, m)                               \
  55.     for (int i = 0; i < n; i++)                         \
  56.         for (int j = 0; j < m && cin >> vec[i][j]; j++) \
  57.             ;
  58. #define cout_2d(vec, n, m)                                      \
  59.     for (int i = 0; i < n; i++, cout << "\n")                   \
  60.         for (int j = 0; j < m && cout << vec[i][j] << " "; j++) \
  61.     // freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  62.  
  63.  
  64.  
  65.  
  66.  
  67. int main()
  68. {
  69.     #ifndef ONLINE_JUDGE
  70.     freopen("input.txt", "r", stdin),
  71.     freopen("output.txt", "w", stdout);
  72. #endif
  73.  
  74.     HABIBA
  75.     set < pair < ll , ll >>st;
  76.     st.insert(make_pair(0 , 0));
  77.     ll n;                     cin >> n;
  78.     string s;                 cin >> s;
  79.     ll t1 = 0 , t2 = 0;
  80.     for(int i = 0; i < n; i++){
  81.         if(s[i] == 'U')
  82.             t2++;
  83.         if(s[i] == 'D')
  84.              t2--;
  85.         if(s[i] == 'L')
  86.             t1--;
  87.         if(s[i] == 'R')
  88.             t1++;
  89.         ll hbd = sz(st);
  90.         st.insert(make_pair(t1 , t2));
  91.         if(hbd == sz(st))
  92.         return cout << "YES" , 0;
  93.  
  94.        
  95.     }
  96.  
  97.     cout << "NO";
  98.  
  99.     return 0 ;
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement