fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string ss;
  4. int N,R=0,L=0,U=0,D=0;
  5. int main() {
  6. cin>>N>>ss;
  7. for(int q=0;q<N-1;q=q+1){
  8. if((ss[q]=='R' and ss[q+1]=='L') or (ss[q]=='L' and ss[q+1]=='R')){
  9. cout<<"Yes";
  10. return 0;
  11. }
  12. else if((ss[q]=='U' and ss[q+1]=='D') or (ss[q]=='D' and ss[q+1]=='U')){
  13. cout<<"Yes";
  14. return 0;
  15. }
  16. }
  17. for(int q=0;q<N-3;q=q+1){
  18. R=0;
  19. L=0;
  20. U=0;
  21. D=0;
  22. for(int w=0;w<4;w=w+1){
  23. if(ss[q+w]=='R'){
  24. R+=1;
  25. }
  26. else if(ss[q+w]=='L'){
  27. L+=1;
  28. }
  29. else if(ss[q+w]=='U'){
  30. U+=1;
  31. }
  32. else if(ss[q+w]=='D'){
  33. D+=1;
  34. }
  35. }
  36. if(R==1 and L==1 and U==1 and D==1){
  37. cout<<"Yes";
  38. return 0;
  39. }
  40. }
  41. cout<<"No";
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5304KB
stdin
20
URDDLLUUURRRDDDDLLLL

stdout
No