No.884 Eat and Add
Problem Statement
There is one plate in front of you, with $N$ apples on it.
Find the minimum number of operations needed to empty the plate by repeatedly performing either of the following operations. The two operations may be performed in any order.
- Choose a non-negative integer $k$ and eat $2^k$ apples from the plate. This operation cannot be performed if the plate does not have at least $2^k$ apples.
- Choose a non-negative integer $k$ and add $2^k$ apples to the plate.
Input
$N$
$1 \le N \lt 2^{200000}$
$N$ is an integer, given in binary without extra leading zeros.
Output
Output the minimum number of operations. Print a newline at the end.
Sample
Sample 1
Input
101
Output
2
There are 5 apples, and you can, for example, operate as follows.
- Eat $2^2=4$ apples
- Eat $2^0=1$ apple
Sample 2
Input
111
Output
2
You can add 1 apple to the 7 apples and then eat 8 apples.
Sample 3
Input
11110101101110110001100
Output
8
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
QCFium
e869120