QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#9040. 减少与交换

Statistics

David Liu 有 $n$ 个排成一行的盒子,记从左往右第 $i$ 个盒子为盒子 $i$,编号从 $1$ 到 $n$。初始时每个盒子都是空的。

Frank 有一个长度为 $n$ 的二进制字符串 $s$。对于每个满足 $s_i = 1$ 的 $i$,他会在盒子 $i$ 中放入 $10^{18}$ 颗石头;对于每个满足 $s_i = 0$ 的 $i$,他会在盒子 $i$ 中放入 $0$ 颗石头。

之后,David Liu 试图移除所有盒子中的每一颗石头。然而,他不能直接把石头拿出来,只能通过执行零次或多次以下操作来实现:

  • 选择一个整数 $i$,满足 $1 \le i \le n - 2$ 且盒子 $i$ 中至少有一颗石头。然后,他必须从盒子 $i$ 中取走一颗石头,并交换盒子 $i + 1$ 和盒子 $i + 2$ 中的内容。

由于石头数量非常多,David Liu 想在尝试之前问你,是否有可能移除所有盒子中的每一颗石头。

回想一下,二进制字符串是指仅包含 $0$ 和 $1$ 的字符串。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^6$),表示测试用例的数量。

每个测试用例包含两行输入。 每个测试用例的第一行包含一个整数 $n$ ($3 \le n \le 10^6$),表示盒子的数量。 每个测试用例的第二行包含一个长度为 $n$ 的二进制字符串,表示 Frank 是否会在每个盒子中放入石头。

保证所有测试用例中 $n$ 的总和不超过 $10^6$。

输出格式

对于每个测试用例,如果 David Liu 可以移除所有石头,则输出 Yes,否则输出 No

样例

样例输入 1

3
3
101
4
1010
5
00000

样例输出 1

No
Yes
Yes

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.