No.3114 0→1
タグ : / 解いたユーザー数 146
作問者 :
Problem Statement
A string consisting of $0$ and $1$ is called a good string $X$ when the following condition is satisfied.
- For every contiguous substring $Y$ of $X$ with length at least 2, the number of $0$ in $Y$ is less than or equal to the number of $1$ in $Y$.
For example, $101$ is a good string. On the other hand, $10011$ contains $00$ as a substring, and the number of $0$ in this string (2) is greater than the number of $1$ (0), so it is not a good string.
You are given a string $S$ of length $N$ consisting of $0$ and $1$. In one operation, you can choose one $0$ in $S$ and change it to $1$.
Find the minimum number of operations required to make $S$ a good string.
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $S$ is a string of length $N$ consisting only of $0$ and $1$
- $N$ is an integer
Input
The input is given from standard input in the following format.
$N$ $S$
Output
Print on one line the minimum number of operations required to make $S$ a good string, followed by a newline.
Sample
Sample 1
Input
5 01001
Output
1
$S$ is not a good string, because the contiguous substring $00$ formed by the 3rd and 4th characters contains 2 occurrences of $0$ but 0 occurrences of $1$.
Also, it can be confirmed that changing the 3rd character of $S$ to $1$ makes $S$ a good string. Therefore, the minimum number of operations required is 1.
Sample 2
Input
6 111111
Output
0
Sample 3
Input
10 1010010001
Output
3
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。