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.