Codeforces Round 979 (Div. 2)
C
A TRUE Battle
Codeforces
1100
原题
← BD →
翻译中…

Alice and Bob are playing a game. There is a list of $n$ booleans, each of which is either true or false, given as a binary string $^{\text{∗}}$ of length $n$ (where $\texttt{1}$ represents true, and $\texttt{0}$ represents false). Initially, there are no operators between the booleans.

翻译中…

Alice and Bob will take alternate turns placing and or or between the booleans, with Alice going first. Thus, the game will consist of $n-1$ turns since there are $n$ booleans. Alice aims for the final statement to evaluate to true, while Bob aims for it to evaluate to false. Given the list of boolean values, determine whether Alice will win if both players play optimally.

翻译中…

To evaluate the final expression, repeatedly perform the following steps until the statement consists of a single true or false:

翻译中…
  • If the statement contains an and operator, choose any one and replace the subexpression surrounding it with its evaluation.
  • Otherwise, the statement contains an or operator. Choose any one and replace the subexpression surrounding the or with its evaluation.
翻译中…

For example, the expression

翻译中…

true or false and false

翻译中…

is evaluated as

翻译中…

true or (false and false)

翻译中…

$=$

翻译中…

true or false

翻译中…

$=$

翻译中…

true

翻译中…

. It can be shown that the result of any compound statement is unique.

翻译中…

$^{\text{∗}}$A binary string is a string that only consists of characters $\texttt{0}$ and $\texttt{1}$

翻译中…

Input

翻译中…

The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains an integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the length of the string.

翻译中…

The second line contains a binary string of length $n$, consisting of characters $\texttt{0}$ and $\texttt{1}$ — the list of boolean values.

翻译中…

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

翻译中…

Output

翻译中…

For each testcase, output "YES" (without quotes) if Alice wins, and "NO" (without quotes) otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

In the first testcase, Alice can place and between the two booleans. The game ends as there are no other places to place operators, and Alice wins because true and true is true.

翻译中…

In the second testcase, Alice can place or between the middle true and the left false. Bob can place and between the middle true and the right false. The statement false or true and false is false.

翻译中…

Note that these examples may not be the best strategies for either Alice or Bob.

翻译中…

样例

Input #1
5
2
11
3
010
12
101111111100
10
0111111011
8
01000010
Output #1
YES
NO
YES
YES
NO
InputCopy OutputCopy
题目信息
题号
2030C
时间限制
2 s
内存限制
256 MB
标签
暴力
博弈论
贪心

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