Upload code_segments/segment_364.txt with huggingface_hub
Browse files
code_segments/segment_364.txt
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You have a binary string$^{\text{∗}}$ $s$ of length $n$, and Iris gives you another binary string $r$ of length $n-1$.
|
2 |
+
|
3 |
+
Iris is going to play a game with you. During the game, you will perform $n-1$ operations on $s$. In the $i$-th operation ($1 \le i \le n-1$):
|
4 |
+
|
5 |
+
* First, you choose an index $k$ such that $1\le k\le |s| - 1$ and $s_{k} \neq s_{k+1}$. If it is impossible to choose such an index, you lose; * Then, you replace $s_ks_{k+1}$ with $r_i$. Note that this decreases the length of $s$ by $1$.
|
6 |
+
|
7 |
+
If all the $n-1$ operations are performed successfully, you win.
|
8 |
+
|
9 |
+
Determine whether it is possible for you to win this game.
|
10 |
+
|
11 |
+
$^{\text{∗}}$A binary string is a string where each character is either $\mathtt{0}$ or $\mathtt{1}$.
|
12 |
+
|
13 |
+
Each test contains multiple test cases. The first line of the input contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. The description of test cases follows.
|
14 |
+
|
15 |
+
The first line of each test case contains a single integer $n$ ($2\le n\le 10^5$) — the length of $s$.
|
16 |
+
|
17 |
+
The second line contains the binary string $s$ of length $n$ ($s_i=\mathtt{0}$ or $\mathtt{1}$).
|
18 |
+
|
19 |
+
The third line contains the binary string $r$ of length $n-1$ ($r_i=\mathtt{0}$ or $\mathtt{1}$).
|
20 |
+
|
21 |
+
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
|
22 |
+
|
23 |
+
For each test case, print "YES" (without quotes) if you can win the game, and "NO" (without quotes) otherwise.
|
24 |
+
|
25 |
+
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
|
26 |
+
|
27 |
+
In the first test case, you cannot perform the first operation. Thus, you lose the game.
|
28 |
+
|
29 |
+
In the second test case, you can choose $k=1$ in the only operation, and after that, $s$ becomes equal to $\mathtt{1}$. Thus, you win the game.
|
30 |
+
|
31 |
+
In the third test case, you can perform the following operations: $\mathtt{1}\underline{\mathtt{10}}\mathtt{1}\xrightarrow{r_1=\mathtt{0}} \mathtt{1}\underline{\mathtt{01}} \xrightarrow{r_2=\mathtt{0}} \underline{\mathtt{10}} \xri
|