C. A-B Palindrome
You are given a string consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string by '0' or '1' so that the string becomes a palindrome and has exactly characters '0' and exactly characters '1'. Note that each of the characters '?' is replaced independently from the others.
A string of length is called a palindrome if the equality is true for all ().
For example, if "01?????0", and , then you can replace the characters '?' in the following ways:
- "01011010";
- "01100110".
For the given string and the numbers and , replace all the characters with '?' in the string by '0' or '1' so that the string becomes a palindrome and has exactly characters '0' and exactly characters '1'.
The first line contains a single integer (). Then test cases follow.
The first line of each test case contains two integers and (, ).
The second line of each test case contains the string of length , consisting of the characters '0', '1', and '?'.
It is guaranteed that the sum of the string lengths of over all test cases does not exceed .
For each test case, output:
- "-1", if you can't replace all the characters '?' in the string by '0' or '1' so that the string becomes a palindrome and that it contains exactly characters '0' and exactly characters '1';
- the string that is obtained as a result of the replacement, otherwise.
If there are several suitable ways to replace characters, you can output any.
9 4 4 01?????0 3 3 ?????? 1 0 ? 2 2 0101 2 2 01?0 0 1 0 0 3 1?1 2 2 ?00? 4 3 ??010?0
01011010 -1 0 -1 0110 -1 111 1001 0101010
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.