#P2708. 硬币翻转

硬币翻转

Description

There are many coins placed in a row. Heads-up is represented by 11, and tails-up is represented by 00.

Starting from the first coin in the row, in each operation you must flip the first several coins simultaneously, i.e., choose some k1k \ge 1 and flip the first kk coins. What is the minimum number of such operations needed to make all coins heads-up?

Input Format

A string consisting of 00 and 11, representing the initial state of the coins.

Output Format

An integer, the minimum number of flips required.

10
2

Hint

Sample Explanation

For example, for input 10:

  • The 11-st flip: flip the first coin to tails; the string becomes 00.
  • The 22-nd flip: flip the first and second coins together to heads; the string becomes 11. Flipping is complete, so the output is 22.

Constraints

Let nn be the total number of coins.

  • For 20%20\% of the testdata, 1n101\le n\leq10.
  • For 50%50\% of the testdata, 1n1041\le n\leq10^4.
  • For 100%100\% of the testdata, 1n1061\le n\leq10^6.

Translated by ChatGPT 5