#P9211. 「不死鸟附体」
「不死鸟附体」
Background
To die and be reborn, to live and die again. A phoenix is such a creature, endlessly repeating this cycle through infinite time.
So it is probably best not to gain eternal youth and immortality.
Problem Description
A phoenix’s “life” can be seen as a string of length at most . After endless cycles, it forms an infinite string . Now take the first characters of as the phoenix’s life within the observable time, denoted by .
However, the so-called cycle is not a rigid mechanical repetition. Therefore, in , no more than characters are changed into other characters, becoming .
Now we have observed , and we want to find the period of this cycle. But since the phoenix’s cycle is far too long, we only want to find a string such that the generated from it can be turned into by modifying no more than characters.
Input Format
The first line contains four positive integers .
The second line describes the observed string of length .
Output Format
Output a positive integer on the first line, representing the length of the you found. You must guarantee .
Output a string of length on the second line, representing the string you found.
25 8 5 10
aaacdaabbbaabccaabcdaabcd
5
aaacd
Hint
Sample Explanation
The sample is only for understanding the statement, and does not satisfy the Constraints. For the actual constraints, see “Constraints and Conventions”.
The used to generate is .
- It generates $S_{\mathrm{inf}}=\verb!aabcdaabcdaabcdaabcdaabcd!\cdots$;
- It generates ;
- It generates $S_{\mathrm{real}\kern{-2.5pt}}=\verb!aaacdaabbbaabccaabcdaabcd!$.
The sample output gives one possible . From this we compute the difference between and :
$$\begin{aligned} S_{\mathrm{fin}}'=&\texttt{aaacdaa\textcolor{red}a\textcolor{red}c\textcolor{red}daa\textcolor{red}ac\textcolor{red}daa\textcolor{red}acdaa\textcolor{red}acd}\cr S_{\mathrm{real}}=&\texttt{aaacdaabbbaabccaabcdaabcd}\cr \end{aligned}$$The difference is , not exceeding , so it is acceptable.
Constraints and Conventions
For all testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5