Henry Porter and the Palindromic Radius
Time limit25sMemory limit512 MB
Given the palindromic radius at every position of an unknown binary string, the task is to list all binary strings that produce exactly those radii.
- Level
Medium7 of 10
- Topics
- String matching, String, Implementation
- Solved
- No attempts yet
Problem
A young wizard, Henry Porter, has just received sad news. His eldest relative, uncle Markus Radius Palindromus Black, has passed away. Uncle Markus was known as an eccentric person who used complicated binary magic, and he was also very, very rich.
Black's will states that Henry should inherit his mysterious chamber of treasures. To enter and claim it, however, the young wizard must say the right password , a word of length consisting of characters 0 and 1. Uncle Markus did not tell Henry the password. Instead, for every , he computed the palindromic radius , the largest integer such that the word of length centered at exists and is a palindrome. Henry only received the values . For example, if the password was 10111010, Henry would get the sequence .
Henry would rather Uncle Markus not test his algorithmic skills from beyond the grave, but he has good friends who can help. Given the sequence left in the will, determine all possible passwords that match it. Since the will is battered and stained, it may happen that there is no solution at all.
Input
The first line contains the number of test cases (). Each test case consists of two lines. The first line contains a single integer , the length of both the password and Black's sequence (). The second line contains integers (), the palindromic radii. The sum of over all test cases does not exceed .
Output
For every test case, first output the number of possible passwords. If , output the passwords on the next lines as -sequences in lexicographic order. You may assume that does not exceed 100.