QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#18133. 替换

Estadísticas

你有一个长度为 $n$ 的二进制字符串 $s$,Iris 给了你另一个长度为 $n - 1$ 的二进制字符串 $r$。

Iris 将和你进行一场游戏。在游戏过程中,你将对 $s$ 执行 $n - 1$ 次操作。在第 $i$ 次操作($1 \le i \le n - 1$)中:

  • 首先,你选择一个下标 $k$,使得 $1 \le k \le |s| - 1$ 且 $s_k \neq s_{k+1}$。如果无法选择这样的下标,则你输掉游戏;
  • 然后,你将 $s_k s_{k+1}$ 替换为 $r_i$。注意,这会使 $s$ 的长度减少 1。

如果所有 $n - 1$ 次操作都成功执行,则你获胜。

请确定你是否可能赢得这场游戏。

输入格式

每个测试包含多个测试用例。输入的第一行包含一个整数 $t$ ($1 \le t \le 10^4$),表示测试用例的数量。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($2 \le n \le 10^5$),表示 $s$ 的长度。 第二行包含长度为 $n$ 的二进制字符串 $s$ ($s_i = 0$ 或 $1$)。 第三行包含长度为 $n - 1$ 的二进制字符串 $r$ ($r_i = 0$ 或 $1$)。

保证所有测试用例的 $n$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,如果你能赢得游戏,打印 “YES”(不含引号),否则打印 “NO”(不含引号)。

你可以以任何大小写形式输出答案。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 都将被识别为肯定回答。

*二进制字符串是指每个字符均为 0 或 1 的字符串。

样例

输入格式 1

6
2
11
0
2
01
1
4
1101
001
6
111110
10000
6
010010
11010
8
10010010
0010010

输出格式 1

NO
YES
YES
NO
YES
NO

说明

在第一个测试用例中,你无法执行第一次操作。因此,你输掉了游戏。

在第二个测试用例中,你可以在唯一的一次操作中选择 $k = 1$,之后 $s$ 变为 1。因此,你赢得了游戏。

在第三个测试用例中,你可以执行以下操作:$1101 \xrightarrow{r_1=0} 101 \xrightarrow{r_2=0} 10 \xrightarrow{r_3=1} 1$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.