Codeforces Round 1014 (Div. 2)
B
Lady Bug
Codeforces
1000
原题
← AC →
翻译中…

As soon as Dasha Purova crossed the border of France, the villain Markaron kidnapped her and placed her in a prison under his large castle. Fortunately, the wonderful Lady Bug, upon hearing the news about Dasha, immediately ran to save her in Markaron's castle. However, to get there, she needs to crack a complex password.

翻译中…

The password consists of two bit strings $a$ and $b$, each of which has a length of $n$. In one operation, Lady Bug can choose any index $2 \le i \le n$ and perform one of the following actions:

翻译中…
  1. swap($a_i$, $b_{i-1}$) (swap the values of $a_i$ and $b_{i-1}$), or
  2. swap($b_i$, $a_{i-1}$) (swap the values of $b_i$ and $a_{i-1}$).
翻译中…

Lady Bug can perform any number of operations. The password is considered cracked if she can ensure that the first string consists only of zeros. Help her understand whether or not she will be able to save the unfortunate Dasha.

翻译中…

Input

翻译中…

Each test consists of several test cases. The first line of the input data contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains one integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the length of the bit strings of the password.

翻译中…

The next two lines contain the bit strings of length $n$, $a$ and $b$, which represent the password. Each of the strings contains only the characters 0 and '1'.

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output "YES" if Lady Bug can crack the password after any number of operations; otherwise, output "NO".

翻译中…

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

翻译中…

Note

翻译中…

In the first test case, the string $a$ immediately consists only of zeros.

翻译中…

In the second test case, a possible sequence of operations is:

翻译中…
  1. swap$(a_2, \ b_{1})$$\mathtt{0{\color{red}{1}}0001}$$\mathtt{{\color{red}{0}}10111}$
  2. swap$(b_5, \ a_{4})$$\mathtt{000{\color{red}{0}}01}$$\mathtt{1101{\color{red}{1}}1}$
  3. swap$(a_4, \ b_{3})$$\mathtt{000{\color{red}{1}}01}$$\mathtt{11{\color{red}{0}}101}$
  4. swap$(a_5, \ b_{4})$$\mathtt{00000{\color{red}{1}}}$$\mathtt{1111{\color{red}{0}}1}$
翻译中…

样例

Input #1
4
3
000
000
6
010001
010111
5
10000
01010
2
11
00
Output #1
YES
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2092B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。