#abc370c. C - Word Ladder
C - Word Ladder
Score : points
问题陈述
你有两个由小写英文字母组成的字符串 和 。这里, 和 的长度相等。
设 为一个空数组,并重复以下操作直到 等于 :
- 改变 中的一个字符,并将 追加到 的末尾。
找到以这种方式获得的元素数量最少的字符串数组 。如果有多个这样的数组具有最少的元素数量,请找到它们中字典序最小的一个。
字典序在字符串数组上是如何定义的?
长度为 的字符串 比长度为 的字符串 字典序更小,如果存在一个整数 满足以下两个条件:
- 在字母顺序中比 更早。
具有 个元素的字符串数组 比具有 个元素的字符串数组 字典序更小,如果存在一个整数 满足以下两个条件:
- $(X_1,X_2,\ldots,X_{j-1}) = (Y_1,Y_2,\ldots,Y_{j-1})$
- 比 字典序更小。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given two strings and consisting of lowercase English letters. Here, and have equal lengths.
Let be an empty array, and repeat the following operation until equals :
- Change one character in , and append to the end of .
Find the array of strings with the minimum number of elements obtained in this way. If there are multiple such arrays with the minimum number of elements, find the lexicographically smallest one among them.
What is lexicographical order on arrays of strings?
A string of length is lexicographically smaller than a string of length if there exists an integer such that both of the following are satisfied:
- comes earlier than in alphabetical order.
An array of strings with elements is lexicographically smaller than an array of strings with elements if there exists an integer such that both of the following are satisfied:
- $(X_1,X_2,\ldots,X_{j-1}) = (Y_1,Y_2,\ldots,Y_{j-1})$
- is lexicographically smaller than .
Constraints
- and are strings consisting of lowercase English letters with length between and , inclusive.
- The lengths of and are equal.
Input
The input is given from Standard Input in the following format:
Output
Let be the number of elements in the desired array. Print lines.
The first line should contain the value of .
The -th line should contain the -th element of the array.
Sample Input 1
adbe
bcbc
Sample Output 1
3
acbe
acbc
bcbc
Initially, adbe
.
We can obtain acbe
acbc
bcbc
by performing the following operations:
-
Change to
acbe
and appendacbe
to the end of . -
Change to
acbc
and appendacbc
to the end of . -
Change to
bcbc
and appendbcbc
to the end of .
Sample Input 2
abcde
abcde
Sample Output 2
0
Sample Input 3
afwgebrw
oarbrenq
Sample Output 3
8
aawgebrw
aargebrw
aarbebrw
aarbebnw
aarbebnq
aarbeenq
aarbrenq
oarbrenq