P19345 [CodeChef] MAKELENGTH1
普及
题目描述

You are given a binary string S of length N.

You can perform the following operation on S:
Select an index i \ (1 ≤ i < |S|) such that S_{i}=S_{i+1}.
Set S_{i} to 0 and remove S_{i+1} from the string.

Note that after each operation, the length of S decreases by 1.

Is it possible to reduce S to a single character by performing the mentioned operation exactly N-1 times?

------ Input Format ------

  • The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of two lines of input.
  • The first line of each test case contains a single integer N, the length of S.
  • The second line contains a binary string S of length N.

------ Output Format ------

For each test case, print the answer on a new line: YES if it is possible to perform the operation N-1 times, and NO otherwise.

Each character of the output may be printed in either uppercase or lowercase, i.e, YES, yes, yEs and yES will all be treated as identical.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 2 \cdot 10^{5}$
- The sum of $N$ over all test cases doesn't exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
4
2
11
2
10
4
1100
3
101

----- Sample Output 1 ------
YES
NO
YES
NO

----- explanation 1 ------
Test case $1$: Perform the operation choosing $i = 1$. This sets $S_{1} = 0$ and deletes $S_{2}$ from the string, after which $S$ is now a single character.

Test case $2$: It is not possible to perform any operation.

Test case $3$: One sequence of operations is as follows:
- Perform the operation on $i = 3$. Now, $S = 110$.
- Perform the operation on $i = 1$. Now, $S = 00$.
- Perform the operation on $i = 1$. Now, $S = 0$ and we are done.

Test case $4$: It is not possible to perform any operation.

输入格式

见题面

输出格式

见题面

样例输入
4 2 11 2 10 4 1100 3 101
样例输出
YES NO YES NO