[Solution] Equal Binary Subsequences Codeforces Solution
Everool has a binary string of length . Note that a binary string is a string consisting of only characters and . He wants to partition into two disjoint equal subsequences. He needs your help to do it.
You are allowed to do the following operation exactly once.
- You can choose any subsequence (possibly empty) of and rotate it right by one position.
In other words, you can select a sequence of indices , where . After that you simultaneously set
Can you partition into two disjoint equal subsequences after performing the allowed operation exactly once?
A partition of into two disjoint equal subsequences and is two increasing arrays of indices and , such that each integer from to is encountered in either or exactly once, , , and .
If it is not possible to partition after performing any kind of operation, report .
If it is possible to do the operation and partition into two disjoint subsequences and , such that , print elements of and indices of , i. e. the values .
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains a single integer (), where is the length of the binary string.
The second line of each test case contains the binary string of length .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, follow the following output format.
If there is no solution, print .
Otherwise,
- In the first line, print an integer (), followed by distinct indices , , ..., (in increasing order).
- In the second line, print distinct indices , , ..., (in increasing order).
If there are multiple solutions, print any.
In the first test case, is empty. So string is not changed. Now , and .
In the second test case, . Initially , , and . On performing the operation, we simultaneously set , and .
So is updated to 101000 on performing the operation.
Now if we take characters at indices in , we get . Also characters at indices are in . Thus . We are done as .
In fourth test case, it can be proved that it is not possible to partition the string after performing any operation.
No comments:
Post a Comment