301483: CF279E. Beautiful Decomposition

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Beautiful Decomposition

题意翻译

### 题目描述 给定一个长度不超过 $10^6$ 的二进制数 $s$,求至少要用几个 $2^k$ 和 $-2^k(k\ge0)$ 加起来值等于 $n$。 ### 输入格式 仅一行包含字符串 $s(1\le|s|\le10^6)$。 ### 输出格式 输出一个整数表示最少的次数 by [@_I°Fear](https://www.luogu.com.cn/user/326452)

题目描述

Valera considers a number beautiful, if it equals $ 2^{k} $ or - $ 2^{k} $ for some integer $ k $ $ (k>=0) $ . Recently, the math teacher asked Valera to represent number $ n $ as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number $ n $ into beautiful summands, you need to find the size of the decomposition which has the fewest summands.

输入输出格式

输入格式


The first line contains string $ s $ $ (1<=|s|<=10^{6}) $ , that is the binary representation of number $ n $ without leading zeroes $ (n&gt;0) $ .

输出格式


Print a single integer — the minimum amount of beautiful numbers that give a total of $ n $ .

输入输出样例

输入样例 #1

10

输出样例 #1

1

输入样例 #2

111

输出样例 #2

2

输入样例 #3

1101101

输出样例 #3

4

说明

In the first sample $ n=2 $ is a beautiful number. In the second sample $ n=7 $ and Valera can decompose it into sum $ 2^{3}+(-2^{0}) $ . In the third sample $ n=109 $ can be decomposed into the sum of four summands as follows: $ 2^{7}+(-2^{4})+(-2^{2})+2^{0} $ .

Input

题意翻译

### 题目描述 给定一个长度不超过 $10^6$ 的二进制数 $s$,求至少要用几个 $2^k$ 和 $-2^k(k\ge0)$ 加起来值等于 $n$。 ### 输入格式 仅一行包含字符串 $s(1\le|s|\le10^6)$。 ### 输出格式 输出一个整数表示最少的次数 by [@_I°Fear](https://www.luogu.com.cn/user/326452)

加入题单

算法标签: