Cowntact Tracing 2

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

요약
감염 여부를 나타낸 최종 비트열이 주어질 때, 0일차에 감염되어 있었을 수 있는 소의 최소 수를 구한다.
난이도

보통10점 중 5점

유형
그리디, 구현, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Farmer John has NN cows in a line (1≤N≤3⋅1051 \leq N \leq 3\cdot 10^5). Unfortunately, there is a sickness spreading throughout.

Initially, some cows start off infected. Every night, an infected cow spreads the sickness to the cows on their left and right (if they exist). Once a cow is infected, she stays infected.

After some amount of nights, Farmer John realizes that the issue has gotten out of control, so he tests his cows to determine who has the sickness. Find the minimum number of cows that could have started with the sickness.

입력

The first line contains NN, the number of cows that Farmer John has.

The next line contains an NN character bitstring of only 11s and 00s where a 11 represents an infected cow and a 00 represents an uninfected cow after some number of nights.

출력

Output a single integer: the minimum number of cows that could have started with the sickness.

예제2

  1. 예제 1

    입력
    5
    11111
    
    예상 출력
    1
    
  2. 예제 2

    입력
    6
    011101
    
    예상 출력
    4