#P15962. [ICPC 2018 Jakarta R] Binary String
[ICPC 2018 Jakarta R] Binary String
题目描述
A binary string is a non-empty sequence of 0’s and 1’s, e.g., 010110, 1, 11101, etc. Ayu has a favorite binary string which contains no leading zeroes. She wants to convert into its decimal representation with her calculator.
Unfortunately, her calculator cannot work on any integer larger than and it will crash. Therefore, Ayu may need to remove zero or more bits from while maintaining the order of the remaining bits such that its decimal representation is no larger than . The resulting binary string also must not contain any leading zeroes.
Your task is to help Ayu to determine the minimum number of bits to be removed from to satisfy Ayu’s need.
For example, let and . Note that is in decimal representation, thus, we need to remove several bits from to make it no larger than . We can remove the , , and most significant bits, i.e. . The decimal representation of is , which is no larger than . In this example, we removed bits, and this is the minimum possible (If we remove only bits, then we will have a binary string of length bits; notice that any binary string of length bits has a value of at least in decimal representation).
输入格式
Input begins with a line containing an integer () representing the limit of Ayu’s calculator. The second line contains a binary string () representing Ayu’s favorite binary string. You may safely assume contains no leading zeroes.
输出格式
Output contains an integer in a line representing the minimum number of bits to be removed from .
13
1100101
3
13
1111111
4
提示
Explanation for the sample input/output #1
This sample is illustrated by the example given in the problem description above.
Explanation for the sample input/output #2
Ayu must remove bits to get , which is in its decimal representation.