QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#18133. 置換

統計

長さ $n$ の二進文字列 $s$* と、長さ $n-1$ の別の二進文字列 $r$ が与えられます。 Iris はあなたとゲームを行います。ゲーム中、あなたは $s$ に対して $n-1$ 回の操作を行います。$i$ 回目の操作 ($1 \le i \le n-1$) では、以下の手順を行います。

  • まず、$1 \le k \le |s| - 1$ かつ $s_k \neq s_{k+1}$ を満たすインデックス $k$ を選択します。そのようなインデックスを選択できない場合、あなたの負けです。
  • 次に、$s_k s_{k+1}$ を $r_i$ に置き換えます。これにより、$s$ の長さが $1$ 減少することに注意してください。

$n-1$ 回の操作すべてを正常に完了できれば、あなたの勝ちです。 このゲームに勝つことが可能かどうかを判定してください。

*二進文字列とは、各文字が 0 または 1 である文字列のことです。

入力

各テストケースには複数のテストケースが含まれます。入力の最初の行には、テストケースの数を示す単一の整数 $t$ ($1 \le t \le 10^4$) が含まれます。続いて各テストケースの説明が続きます。

各テストケースの最初の行には、$s$ の長さを表す単一の整数 $n$ ($2 \le n \le 10^5$) が含まれます。 2行目には、長さ $n$ の二進文字列 $s$ ($s_i = 0$ または $1$) が含まれます。 3行目には、長さ $n-1$ の二進文字列 $r$ ($r_i = 0$ または $1$) が含まれます。

すべてのテストケースにおける $n$ の総和は $10^5$ を超えないことが保証されています。

出力

各テストケースについて、ゲームに勝てる場合は "YES" を、そうでない場合は "NO" を出力してください(引用符は含めない)。

答えはどのような大文字・小文字の組み合わせでも出力できます。例えば、"yEs"、"yes"、"Yes"、"YES" はすべて正解として認識されます。

入出力例

入力 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

注記

最初のテストケースでは、最初の操作を行うことができません。したがって、あなたの負けです。 2番目のテストケースでは、唯一の操作で $k=1$ を選択でき、その後 $s$ は $1$ になります。したがって、あなたの勝ちです。 3番目のテストケースでは、次のように操作を行うことができます: $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.