問題一覧 > 通常問題

No.2283 Prohibit Three Consecutive

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 102
作問者 : みここ / テスター : cureskol 👑 箱星 👑 potato167
お気に入りにしたユーザー ProblemId : 9168 / 自分の提出
問題文最終更新日: 2023-04-26 18:34:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 386 (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$ consisting of 0, 1, and ?.

Determine whether it is possible to change every ? in $S$ to either 0 or 1 so that the same character does not appear three times in a row in $S$. Here, the end and the beginning of $S$ are considered to be connected.

You are given $T$ test cases; find the answer for each of them.

Input

$T$
test$_1$
$\vdots$
test$_T$

Here, test$_i$ represents the $i$-th test case, given in the following format.

$N$
$S$
  • $T, N$ are integers
  • $S$ is a string of length $N$ consisting of 0, 1, and ?
  • $1 \le T \le 5 \times 10^4$
  • $3 \le N \le 10^5$
  • The sum of $N$ over all test cases does not exceed $2 \times 10^5$

Output

Print Yes if it is possible to prevent the same character from appearing three times in a row in $S$, and No otherwise. Print a newline at the end.

Sample

Sample 1
Input
3
3
1?1
5
11?00
4
1101
Output
Yes
No
No

For the first test case, if the ? at the $2$-nd character is changed to 0, the same character no longer appears three times in a row in $S$.

For the second test case, note that every ? must be changed to either 0 or 1.

For the third test case, since the end and the beginning of $S$ are connected, three 1s appear in a row in $S$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。