#abc370c. C - Word Ladder

C - Word Ladder

Score : 300300 points

问题陈述

你有两个由小写英文字母组成的字符串 SSTT。这里,SSTT 的长度相等。

XX 为一个空数组,并重复以下操作直到 SS 等于 TT

  • 改变 SS 中的一个字符,并将 SS 追加到 XX 的末尾。

找到以这种方式获得的元素数量最少的字符串数组 XX。如果有多个这样的数组具有最少的元素数量,请找到它们中字典序最小的一个。

字典序在字符串数组上是如何定义的?

长度为 NN 的字符串 S=S1S2SNS = S_1 S_2 \ldots S_N 比长度为 NN 的字符串 T=T1T2TNT = T_1 T_2 \ldots T_N 字典序更小,如果存在一个整数 1iN1 \leq i \leq N 满足以下两个条件:

  • S1S2Si1=T1T2Ti1S_1 S_2 \ldots S_{i-1} = T_1 T_2 \ldots T_{i-1}
  • SiS_i 在字母顺序中比 TiT_i 更早。

具有 MM 个元素的字符串数组 X=(X1,X2,,XM)X = (X_1,X_2,\ldots,X_M) 比具有 MM 个元素的字符串数组 Y=(Y1,Y2,,YM)Y = (Y_1,Y_2,\ldots,Y_M) 字典序更小,如果存在一个整数 1jM1 \leq j \leq M 满足以下两个条件:

  • $(X_1,X_2,\ldots,X_{j-1}) = (Y_1,Y_2,\ldots,Y_{j-1})$
  • XjX_jYjY_j 字典序更小。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given two strings SS and TT consisting of lowercase English letters. Here, SS and TT have equal lengths.

Let XX be an empty array, and repeat the following operation until SS equals TT:

  • Change one character in SS, and append SS to the end of XX.

Find the array of strings XX 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 S=S1S2SNS = S_1 S_2 \ldots S_N of length NN is lexicographically smaller than a string T=T1T2TNT = T_1 T_2 \ldots T_N of length NN if there exists an integer 1iN1 \leq i \leq N such that both of the following are satisfied:

  • S1S2Si1=T1T2Ti1S_1 S_2 \ldots S_{i-1} = T_1 T_2 \ldots T_{i-1}
  • SiS_i comes earlier than TiT_i in alphabetical order.

An array of strings X=(X1,X2,,XM)X = (X_1,X_2,\ldots,X_M) with MM elements is lexicographically smaller than an array of strings Y=(Y1,Y2,,YM)Y = (Y_1,Y_2,\ldots,Y_M) with MM elements if there exists an integer 1jM1 \leq j \leq M such that both of the following are satisfied:

  • $(X_1,X_2,\ldots,X_{j-1}) = (Y_1,Y_2,\ldots,Y_{j-1})$
  • XjX_j is lexicographically smaller than YjY_j.

Constraints

  • SS and TT are strings consisting of lowercase English letters with length between 11 and 100100, inclusive.
  • The lengths of SS and TT are equal.

Input

The input is given from Standard Input in the following format:

SS

TT

Output

Let MM be the number of elements in the desired array. Print M+1M + 1 lines.

The first line should contain the value of MM.

The i+1i + 1-th line (1iM)(1 \leq i \leq M) should contain the ii-th element of the array.

Sample Input 1

adbe
bcbc

Sample Output 1

3
acbe
acbc
bcbc

Initially, S=S = adbe.

We can obtain X=(X = ( acbe ,, acbc ,, bcbc )) by performing the following operations:

  • Change SS to acbe and append acbe to the end of XX.

  • Change SS to acbc and append acbc to the end of XX.

  • Change SS to bcbc and append bcbc to the end of XX.

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