CF2188B.Seats

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Cordell manages a row of nn seats at the Scuola Comunale di Musica Piova where students are strictly forbidden from sitting next to each other.

You are given a binary string∗^{\text{∗}} ss, where si=1s_i = \mathtt{1} indicates that the ii-th seat has been occupied by a student, and si=0s_i = \mathtt{0} indicates that it is free now. It is guaranteed that no two adjacent seats are occupied currently. Cordell needs to add more students until it is impossible to seat anyone else in the row. However, she wants to achieve this state with as few students as possible.

Your task is to calculate the minimum total number of students seated when it is impossible to seat anyone else in the row.

∗^{\text{∗}}A binary string is a string where each character is either 0\mathtt{0} or 1\mathtt{1}.

科尔德尔负责管理皮奥瓦社区音乐学校(Scuola Comunale di Musica Piova)一排共 nn 个座位,学生被严格禁止相邻而坐。

你将得到一个二进制字符串∗^{\text{∗}} ss,其中 si=1s_i = \mathtt{1} 表示第 ii 个座位已被一名学生占据,而 si=0s_i = \mathtt{0} 表示该座位当前空闲。题目保证:当前不存在两个相邻的被占据座位。科尔德尔需要继续添加学生,直到整排座位再也无法容纳任何新学生为止。然而,她希望以最少的学生总数达成这一最终状态。

你的任务是:计算当整排座位再也无法容纳任何新学生时,所坐学生的最小总数。

∗^{\text{∗}}所谓二进制字符串,是指其中每个字符均为 0\mathtt{0} 或 1\mathtt{1} 的字符串。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of seats in the row.

The second line of each test case contains the binary string ss of length nn (si∈0,1s_i \in {\mathtt{0}, \mathtt{1}}). It is guaranteed that no two adjacent characters are both 1\mathtt{1}.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示该排座位的数量。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss(si∈0,1s_i \in {\mathtt{0}, \mathtt{1}})。保证不存在两个相邻字符均为 1\mathtt{1}。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the minimum total number of seated students.

对于每个测试用例,输出一个整数——即就座学生的最少总人数。

输入输出样例

  • 输入#1

    5
    1
    0
    3
    000
    5
    00000
    6
    100101
    13
    0000100001000

    输出#1

    1
    1
    2
    3
    5

说明/提示

In the first test case, n=1n = 1 and the hall is initially empty. Because the row is still possible to seat any student, Cordell must place one student at seat 11. Therefore, the minimum number of seated students is 11.

In the third test case, Cordell can place two students at seats 11 and 44. It can be shown that she cannot place only one student so that the row is impossible to seat anyone more, so the answer is 22.

In the fourth test case, no extra students can be seated, so Cordell can place no extra students, and the number of seated students is 33.

在第一个测试用例中,n=1n = 1,且礼堂初始为空。由于该排仍有可能安排任何学生就座,科德尔必须在座位 11 安排一名学生。因此,就座学生的最小数量为 11。

在第三个测试用例中,科德尔可以在座位 11 和 44 各安排一名学生。可以证明,她无法仅安排一名学生便使得该排再也无法安排任何额外的学生,因此答案为 22。

在第四个测试用例中,无法再安排任何额外的学生,因此科德尔不能安排任何额外的学生,就座学生的数量为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页