#P5770. [JSOI2016] 无界单词
[JSOI2016] 无界单词
Description
For a word , if there exists a length such that , and the prefix of with length is the same as the suffix of with length , then JYY calls bordered. For example, aabaa and ababab are both bordered strings. If a word does not have such an , then JYY calls it an unbordered word.
Now consider all strings of length that consist only of the letters a and b. JYY wants to know:
- How many unbordered words are there in total?
- Among these unbordered words, when sorted in lexicographical order, what is the -th smallest word?
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers and , describing one test case.
Output Format
For each test case, output two lines.
The first line contains an integer, the number of unbordered words of length .
The second line contains a string of length , representing the -th smallest unbordered word.
5
5 1
5 2
5 3
5 4
5 5
12
aaaab
12
aaabb
12
aabab
12
aabbb
12
ababb
Hint
For of the testdata, .
For all testdata, , , and it is guaranteed that for every test case, the -th smallest unbordered word always exists.
Translated by ChatGPT 5
京公网安备 11011102002149号