#K11486. Minimum Operations to Turn Off Machines
Minimum Operations to Turn Off Machines
Minimum Operations to Turn Off Machines
You are given a binary string s representing the state of a linear array of machines, where '1' indicates that a machine is ON and '0' indicates it is OFF. In one operation, you can select any machine which is ON, and this operation will turn that machine and its immediate left neighbor (if it exists) OFF. Your task is to determine the minimum number of operations required to turn all machines OFF.
Formally, given a string \( s \) of length \( n \), you are allowed to perform an operation on an index \( i \) (where \( s_i = '1' \)) that sets \( s_i \) and \( s_{i-1} \) (if \( i-1 \ge 0 \)) to '0'. Find the minimum number of such operations so that every character in \( s \) becomes '0'.
Note: It is always optimal to process the string from rightmost end to leftmost end.
inputFormat
The input consists of a single line containing the binary string \( s \) (\( 1 \leq |s| \leq 10^5 \)).
outputFormat
Output a single integer representing the minimum number of operations required to turn all the machines OFF.
## sample1101
2