fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <numeric>
  7. #include <map>
  8. #include <unordered_map>
  9. #include <stack>
  10. #include <queue>
  11. using namespace std;
  12. #define all(a) a.begin(), a.end()
  13. #define ll long long
  14. #define fo(i,n) for (long long i = 0; i < n; i++)
  15. #define pb push_back
  16. int main()
  17. {
  18. ll a,b,c,d,n,m,k,input,i;
  19. ios_base::sync_with_stdio(false);
  20. string one,two,three;
  21. cin.tie(0); cout.tie(0);
  22. cin >> i;
  23. while (i--)
  24. {
  25. bool cond = true;
  26. bool change = false;
  27. cin >> one;
  28. cin >> two;
  29. int l1 = 0;
  30. int l2 = 0;
  31. int r1 = 0;
  32. int r2 = 0;
  33. int a = 0;
  34. int b = 0;
  35. int consecutive = 1;
  36. int color = 0;
  37. while (true)
  38. {
  39. if (b >= two.size())
  40. {
  41. cond = false;
  42. break;
  43. }
  44. change = false;
  45. if (one[a] == 'L')
  46. {
  47. l1++;
  48. }
  49. else
  50. {
  51. r1++;
  52. }
  53. if (one[a] != two[b])
  54. {
  55. if (one[a] == 'L')
  56. {
  57. if (consecutive > 0 && color == 1)
  58. {
  59. consecutive--;
  60. change = true;
  61. }
  62. else
  63. {
  64. cond = false;
  65. break;
  66. }
  67. }
  68. else
  69. {
  70. if (consecutive > 0 && color == 0)
  71. {
  72. consecutive--;
  73. change = true;
  74. }
  75. else
  76. {
  77. cond = false;
  78. break;
  79. }
  80. }
  81. }
  82. if (change == false)
  83. {
  84. if (one[a] == 'R')
  85. {
  86. color = 1;
  87. }
  88. else
  89. {
  90. color = 0;
  91. }
  92. if (a > 0)
  93. {
  94. if (one[a] == one[a-1])
  95. {
  96. consecutive++;
  97. if (one[a] == 'L')
  98. {
  99. color = 0;
  100. }
  101. else
  102. {
  103. color = 1;
  104. }
  105. }
  106. else
  107. {
  108. consecutive = 1;
  109. if (one[a] == 'L')
  110. {
  111. color = 0;
  112. }
  113. else
  114. {
  115. color = 1;
  116. }
  117. }
  118. }
  119. }
  120. if (!change)
  121. {
  122. a++;
  123. }
  124. b++;
  125. if (a == one.size())
  126. {
  127. break;
  128. }
  129. }
  130. while (b < two.size())
  131. {
  132. if (two[b] == 'L')
  133. {
  134. if (color == 0 && consecutive > 0)
  135. {
  136. consecutive--;
  137. }
  138. else
  139. {
  140. cond = false;
  141. break;
  142. }
  143. }
  144. else
  145. {
  146. if (color == 1 && consecutive > 0)
  147. {
  148. consecutive--;
  149. }
  150. else
  151. {
  152. cond = false;
  153. break;
  154. }
  155. }
  156. b++;
  157. }
  158. if (cond)
  159. {
  160. cout << "YES";
  161. }
  162. else
  163. {
  164. cout << "NO";
  165. }
  166. cout << endl;
  167. }
  168. }
Success #stdin #stdout 0.01s 5284KB
stdin
1
LRL
LLRR

stdout
NO