#C5715. Beautiful Binary String Transformation
Beautiful Binary String Transformation
Beautiful Binary String Transformation
You are given a binary string s. A string is called beautiful if it does not contain the substring 010
. In one move, you can change an occurrence of 010
to 101
(or vice versa). Your task is to determine the minimum number of moves required to transform the given string into a beautiful string.
Note: In each move, you can operate on non-overlapping substrings. For example, for the input 0101010
, the minimum number of moves required is 2
.
The problem can be mathematically described by counting the number of non-overlapping occurrences of the substring 010
in the string. In other words, if we denote the string by s, then the answer is given by:
inputFormat
The input consists of a single line containing a binary string s
(i.e. a string consisting only of the characters '0' and '1').
outputFormat
Output a single integer - the minimum number of moves required to transform the string into a beautiful string.
## sample0101010
2