Occupy the Cities

시간 제한1초메모리 제한1024 MB

요약
길이 n의 이진 문자열이 주어지고, 매 라운드마다 점령된 도시가 인접한 비점령 도시 하나를 공격 대상으로 표시하면 그 도시들이 점령된다. 모든 도시를 점령하는 최소 라운드 수를 구한다.
난이도

보통10점 중 7점

유형
그리디, 이분 탐색, 구현
정답자
아직 제출이 없습니다

문제

JB is playing a game. There are nn cities in the game, numbered as 1,2,⋯ ,n1, 2, \cdots, n. The ii-th city and the jj-th city are adjacent if and only if i=j−1i = j - 1 or i=j+1i = j + 1. Initially, some of the cities are occupied by JB.

The game runs in rounds. At the beginning of a round, each occupied city can mark at most one adjacent unoccupied city as the target of attack. At the end of the round, all the attack targets marked become occupied. The game ends when all the cities are occupied.

JB wants to occupy all the cities in minimum rounds. Can you help him?

입력

There are multiple test cases. The first line of the test case contains a positive integer TT, indicating the number of test cases. For each test case:

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6), indicating the number of cities.

The next line contains a string ss of length nn. It's guaranteed ss only contains '0' and '1'. The ii-th character describes the initial state of the ii-th city: if s_i=s\_i = '1', the ii-th city is occupied by JB initially. Otherwise, the ii-th city is not occupied initially.

It's guaranteed that the sum of nn over all the test cases doesn't exceed 10610^6. It's also guaranteed that there is at least one '1' in ss.

출력

For each test case, output one line, containing the minimum number of rounds to occupy all the cities.

힌트

For the second test case, the best way is 0100→0110→11110100 \rightarrow 0110 \rightarrow 1111.

예제1

  1. 예제 1

    입력
    5
    3
    010
    4
    0100
    7
    0001000
    5
    11111
    6
    010101
    
    예상 출력
    2
    2
    4
    0
    1