-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2094D.cpp
More file actions
83 lines (70 loc) · 1.24 KB
/
Copy path2094D.cpp
File metadata and controls
83 lines (70 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define umap unordered_map
#define f(i, x, n) for (ll i = x; i < n; i++)
#define endl '\n'
#define optimize() \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int main()
{
optimize();
int t;
cin >> t;
while (t--)
{
string p, s;
cin >> p >> s;
bool ok = true;
for (ll i = 0, j = 0; i < p.size() || j < s.size(); i++, j++)
{
if (!ok)
break;
ll ii = i, jj = j;
string p_test, s_test;
if (p[i] == 'L')
{
while (ii < p.size() && p[ii] == 'L')
{
p_test.pb(p[ii]);
ii++;
}
while (jj < s.size() && s[jj] == 'L')
{
s_test.pb(s[jj]);
jj++;
}
}
else if (p[i] == 'R')
{
while (ii < p.size() && p[ii] == 'R')
{
p_test.pb(p[ii]);
ii++;
}
while (jj < s.size() && s[jj] == 'R')
{
s_test.pb(s[jj]);
jj++;
}
}
if ((p_test.size() > s_test.size() || s_test.size() > 2 * p_test.size()) || p_test.empty() || s_test.empty())
{
ok = false;
}
i = ii - 1, j = jj - 1;
}
if (ok)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
}