Codeforces Global Round 29 (Div. 1 + Div. 2)
C
Rabbits
Codeforces
1500
原题
← BD →
翻译中…

You have $n$ flower pots arranged in a line numbered from $1$ to $n$ left to right. Some of the pots contain flowers, while others are empty. You are given a binary string $s$ describing which pots contain flowers ($s_i = 1$) and which are empty ($s_i = 0$). You also have some rabbits, and you want to take a nice picture of rabbits and flowers. You want to put rabbits in every empty pot ($s_i = 0$), and for each rabbit, you can put it looking either to the left or to the right. Unfortunately, the rabbits are quite naughty, and they will try to jump, which will ruin the picture.

翻译中…

Each rabbit will prepare to jump into the next pot in the direction they are looking, but they won't jump if there is a rabbit in that pot already or if there is another rabbit that prepares to jump into the same pot from the opposite side. Rabbits won't jump out of the borders (a rabbit at pot $1$ looking to the left won't jump, same for a rabbit looking to the right at pot $n$).

翻译中…

Your goal is to choose the directions of the rabbits so that they never jump, allowing you to take your time to take the picture. You need to determine if there is a valid arrangement of rabbits such that no rabbit ever jumps.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$).

翻译中…

The second line contains a binary string $s$ of size $n$, denoting the occupied and empty pots.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, print "YES" if there exists a configuration of rabbits that satisfies the condition, and "NO" otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…
翻译中…

In the first test case, one of the valid configurations is to put a rabbit looking to the right at position $1$, a rabbit looking to the left at position $3$, and a rabbit looking to the left at position $4$. No rabbit will move since:

翻译中…
  • The rabbit at pot $1$ won't move to pot $2$ since the rabbit at pot $3$ is looking to the left.
  • The rabbit at pot $3$ won't move to pot $2$ since the rabbit at pot $1$ is looking to the right.
  • The rabbit at pot $4$ won't move to pot $3$ since there is a rabbit in there.
翻译中…

image

翻译中…

In the second test case, one of the valid configurations is to put a rabbit looking to the left at position $1$, a rabbit looking to the right at position $2$, and a rabbit looking to the left at position $3$. No rabbit will move since:

翻译中…
  • The rabbit at pot $1$ won't move since it is looking at the left border.
  • The rabbit at pot $2$ won't move to pot $3$ since there is a rabbit in there.
  • The rabbit at pot $3$ won't move to pot $2$ since there is a rabbit in there.
翻译中…

image

翻译中…

It can be proven that there is no valid arrangement of rabbits in the third test case.

翻译中…

样例

Input #1
12
4
0100
3
000
8
11011011
5
00100
1
1
5
01011
2
01
7
0101011
7
1101010
5
11001
4
1101
9
001101100
Output #1
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
InputCopy OutputCopy
题目信息
题号
2147C
时间限制
2 s
内存限制
256 MB
标签
构造
动态规划
贪心
模拟

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