問題一覧 > 通常問題

No.3114 0→1

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 146
作問者 : jupiter_68 / テスター : kenken714 ponjuice Nzt3 Naru820
お気に入りにしたユーザー ProblemId : 12152 / 自分の提出
問題文最終更新日: 2025-04-16 06:43:50
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
CPCTF 2025 : PPC (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。