#P2133. 天作之合
天作之合
Description
At Xiaoming’s school, there are several girls. Xiaoming thinks each girl’s traits can be abstracted into a -digit string that contains, without repetition, the digits .
In Xiaoming’s mind, there is an ideal girl whose trait string is . If string is obtained from string by swapping two consecutive digits, then we say that trait strings and are similar. First, Xiaoming finds his deskmate, whose trait string is . Each time, Xiaoming looks for a girl whose trait string is similar to the current string, until he finds one suitable for him (that is, a girl whose trait string is identical to or similar to ). Define each girl’s suitability degree as the minimum number of girls he needs to look for to reach this person (including his deskmate and this person herself). Clearly, the smaller the suitability degree, the more suitable the girl is for Xiaoming.
However, Xiaoming feels that fate will not let him find her easily, so he believes that the second smallest suitability degree is actually his best match (that is, Xiaohong). Please write a program to compute Xiaohong’s suitability degree for Xiaoming.
Input Format
The st line: a trait string .
The nd line: a trait string .
Output Format
One line with a non-negative integer representing Xiaohong’s suitability degree.
123654
123456
3
Hint
Sample explanation:
The two shortest “suitable strings” are and , so the answer is .
For all testdata, it is guaranteed that strings and are valid, and that a solution exists.
Translated by ChatGPT 5
京公网安备 11011102002149号