#P5890. 小欧与回文串构造
小欧与回文串构造
Description
Xiao Ou likes strings, especially palindromic strings that contain only the two characters 0 and 1.
Xiao Ou also likes palindromes, especially strings that have some palindromic substrings, but not too many.
Xiao Ou likes construction even more, so he thinks about the following problem:
Given positive integers and , with guaranteed, can you construct a string of length consisting only of characters 0 and 1, such that the number of essentially different non-empty palindromic substrings of is exactly ?
Xiao Ou is a construction newbie and cannot beat the predecessors who have already brute-forced 100,000 or even 90,000 construction problems, so he asks you to help solve this problem, and hopes that when a solution exists, you can output any valid construction.
Some basic definitions about strings are given below. If you are very familiar with strings, you may skip this part.
- For a string of length , let be the -th character of from left to right.
- For a string of length , define its substring as the string formed by concatenating from left to right. In particular, the empty string is also a substring of .
- Two substrings and of are called essentially different if and only if .
- For a string of length , define its reverse string as the string formed by concatenating from left to right.
- A string is a palindrome if and only if .
Input Format
This problem has multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
One line contains two positive integers, representing and for this test case.
Output Format
For each test case:
If there is no solution, output one line with the string No.
Otherwise, output two lines. The first line is the string Yes, and the next line is a 01 string of length , which is your constructed solution. If there are multiple solutions, output any one.
4
4 4
8 6
15 14
114514 1
Yes
0101
No
Yes
010100000111101
No
Hint
For the first test case, the essentially different palindromic substrings are: 1, 0, 101, 010, for a total of four.
Constraints and Notes
For of the testdata, .
For another of the testdata, .
For another of the testdata, , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号