Masala E
Kamron and Binary String (Easy Version)
This is the easy version of the problem. The difference between the versions is that in this version, string tt consists of only '0' and '1'. You can hack only if you solved all versions of this problem.
Kamron has a binary string of length . Kamron can perform the following operation:
- Choose two adjacent blocks of and swap them.
A block is a maximal of identical characters. Formally, denote as the substring A block is satisfying:
Adjacent blocks are two blocks and satisfying .
For example, if , Kamron can choose the two blocks and and swap them, transforming into .
Given a string t of length n consisting of '0', '1' and '?', Kamron wants to determine the minimum number of operations required to perform such that for any index , if then . If it is impossible, output .
∗∗A string a is a substring of a string b if a can be obtained from b by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
Each test contains multiple test cases. The first line contains the number of test cases . The description of the test cases follows.
The first line of each test case contains a string s consisting of '0' and '1'.
The second line of each test case contains a string t consisting of '0' and '1'.
It is guaranteed that the lengths of s and tt are the same.
It is guaranteed that the sum of the length of ss over all test cases will not exceed .
For each test case, output one integer — the minimum number of operations required. If it is impossible, output −1.
# | input.txt | output.txt |
---|---|---|
1 |
6 0001100111 0000011111 010101 111000 0101 0110 0101 1010 011001 001110 0 1 |
1 3 1 -1 -1 -1 |
In the first test case, the possible way is shown in the statement.
In the second test case, one possible way could be:
- Swap blocks , s will become .
- Swap blocks , s will become .
- Swap blocks , s will become .