atcoder#ARC156A. [ARC156A] Non-Adjacent Flip
[ARC156A] Non-Adjacent Flip
Score : points
Problem Statement
We have coins numbered to with two distinguishable sides. A string represents the current state of the coins. If the -th character of is 1
, coin is showing heads; if that character is 0
, coin is showing tails.
You can repeat the following operation zero or more times.
- Choose a pair of integers such that and . Flip coin and coin .
Determine whether it is possible to make all the coins show tails. If it is possible, find the minimum number of operations needed.
You are given test cases to solve.
Constraints
- is a string of length consisting of
0
and1
. - All numbers in the input are integers.
- For each input file, the sum of over the test cases is at most .
Input
The input is given from Standard Input in the following format:
Each case is in the following format:
Output
Print lines. The -th line should contain the minimum number of operations needed to make all the coins show tails if it is possible, and -1
otherwise.
5
3
101
6
101101
5
11111
6
000000
30
111011100110101100101000000111
1
2
-1
0
8
For the first test case, you can perform the operation with to make all the coins show tails in one operation.
For the second test case, you can perform the operation with and then with to make all the coins show tails in two operations.
For the third test case, you can prove that there is no way to make all the coins show tails, so you should print -1
.
For the fourth test case, the coins already show tails, so no operation is needed.