-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.cpp
More file actions
61 lines (56 loc) · 1.65 KB
/
tempCodeRunnerFile.cpp
File metadata and controls
61 lines (56 loc) · 1.65 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
#include<bits/stdc++.h>
using namespace std;
#define faster_ayman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define testcase int tt;cin >> tt;while (tt--)
#define inf 1e18
typedef vector<int> vi;
typedef vector<pair<int,int>> vp;
typedef vector<double> vd;
typedef vector<char> vc;
typedef set<int> si;
typedef set<char> sc;
typedef unordered_set<int> usi;
signed main() {
faster_ayman
testcase {
int n, m; cin >> n >> m;
string s, t; cin >> s >> t;
bool flag = 0, flag2 = 0;
rep(i, 0, n - 1) {
if (s[i] == s[i + 1]) {
flag = 1;
}
if (t[i] == t[i + 1]) {
flag2 = 1;
}
}
if (!flag) {
cout << "YES\n";
continue;
}
if (flag2 == 1 && flag == 1) {
cout << "NO\n";
continue;
}
bool x = 0;
if (flag2 == 0 && flag == 1) {
rep(i, 0, n - 1) {
if (s[i] == s[i + 1]) {
if (s[i] == t[0] || (s[i + 1] == t[m - 1] && s[i] !=t[0]) ) {
x = 1;
}
}
}
}
if (x) {
cout << "NO\n";
}else {
cout << "YES\n";
}
}
return 0;
}