-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path576-two-towers.cpp
More file actions
54 lines (51 loc) · 1.35 KB
/
Copy path576-two-towers.cpp
File metadata and controls
54 lines (51 loc) · 1.35 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
/*
* Two Towers [1795A]
* Problem: https://codeforces.com/problemset/problem/1795/A
* Verdict: ACCEPTED Solved: 2025-03-20
* Language: C++23 (GCC 14-64, msys2)
* Runtime: 61 ms Memory: 0 KB
* Tags: brute force, implementation, strings
* Author: BidoTeima
* Source: https://codeforces.com/contest/1795/submission/311526002
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
string a,b;
cin>>a>>b;
// find the place where a[i]==a[i-1]
int inA=-1,inB=-1;
for(int i = 1; i < n; i++){
if(a[i]==a[i-1])inA=i;
}
for(int i = 1; i < m; i++){
if(b[i]==b[i-1])inB=i;
}
if(inA != -1){
while((int)a.size() > inA){
b.push_back(a.back());
a.pop_back();
}
}else if(inB != -1) {
while((int)b.size() > inB){
a.push_back(b.back());
b.pop_back();
}
}
bool ok = 1;
for(int i = 1; i < (int)a.size(); i++) if(a[i]==a[i-1])ok=0;
for(int i = 1; i < (int)b.size(); i++) if(b[i]==b[i-1])ok=0;
cout<<(ok?"YES\n":"NO\n");
}
return 0;
}