What a Reversal solution codeforces
You have two strings 0 and 1, and an integer .and of equal length consisting of characters
You need to make stringsand equal.
In one step, you can choose any substring of 1 (and arbitrary number of characters 0) and reverse it. Formally, if , you can choose any integers and ( ) such that there are exactly ones among characters , and set to .containing exactly characters
Find a way to makeequal to using at most reversals of the above kind, or determine that such a way doesn’t exist. The number of reversals doesn’t have to be minimized.
Each test contains multiple test cases. The first line contains the number of test cases( ). Description of the test cases follows.
Each test case consists of three lines. The first line of each test case contains two integersand ( ; ).
The second line contains stringof length .
The third line contains string 0 and 1.of the same length. Both strings consist of characters
It is guaranteed that the sum ofover all test cases does not exceed .
For each test case, if it’s impossible to makeequal to in at most reversals, print a single integer .
Otherwise, print an integer( ), denoting the number of reversals in your sequence of steps, followed by pairs of integers ( ), denoting the boundaries of the substrings of to be reversed, in chronological order. Each substring must contain exactly ones at the moment of reversal.
Note thatdoesn’t have to be minimized. If there are multiple answers, print any.
6 6 1 101010 010101 6 3 101010 010101 6 0 101010 010101 6 6 101010 010101 4 2 0000 1111 9 2 011100101 101001011
3 1 2 3 4 5 6 1 1 6 -1 -1 -1 5 4 8 8 9 3 6 1 4 3 6
In the first test case, after the first reversal 011010, after the second reversal 010110, after the third reversal 010101.