Codeforces Global Round 30 (Div. 1 + Div. 2)
D
Copy String
Codeforces
1800
原题
← CE →
翻译中…

Given two strings $s$ and $t$ of length $n$, you aim to transform $s$ into $t$ through a series of the following operations:

翻译中…
  • Construct a new string $s'$ of length $n$,where $s'_1=s_1$. For each $1 \lt i \le n$, $s'_i$ can be either $s_i$ or $s_{i-1}$. Then replace $s$ with $s'$.
翻译中…

Your task is to achieve this transformation using the minimum number of operations. You also need to output the solution by printing the constructed string $s'$ after each operation. If the transformation cannot be achieved in less than or equal to $k_{\mathrm{max}}$ operations, output -1.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$, $k_{\mathrm{max}}$ ($1 \le n \cdot k_{\mathrm{max}} \le 10^6$) — the length of two strings and the maximum number of operations that can be used.

翻译中…

The second line of each test case contains one string $s$ of length $n$.

翻译中…

The third line of each test case contains one string $t$ of length $n$.

翻译中…

It is guaranteed that the sum of $nk_{\mathrm{max}}$ over all test cases does not exceed $10^6$.

翻译中…

It is guaranteed that both $s$ and $t$ consist of lowercase Latin letters.

翻译中…

Output

翻译中…

For each test case:

翻译中…
  • If you cannot achieve the transformation in less than or equal to $k_{\mathrm{max}}$ operations, simply output -1 in one line.
  • Otherwise, on the first line, output one integer $k \le k_{\mathrm{max}}$ — the minimum number of operations. Then $k$ lines follow, each line contains one string of length $n$ — the string after each operation.
翻译中…

If there are multiple solutions, output any.

翻译中…

Note

翻译中…

In the first test case, obviously $s$ can be transformed to $t$ in one operation.

翻译中…

In the second test case, initially $s=t$, so no operation is needed.

翻译中…

In the fourth test case, although $s$ can be transformed to $t$ in two operations, but $k_{\mathrm{max}}=1$, so the answer is -1.

翻译中…

样例

Input #1
7
4 1
abcd
aabd
2 2
ab
ab
5 3
abcde
abbcc
9 1
egcnyeluw
eegccyelw
10 3
vzvylxxmsy
vvvvvllxxx
4 6
acba
aaac
5 7
acabb
aaaca
Output #1
1
aabd
0
2
abbcd
abbcc
-1
3
vvzvylxxms
vvvzvllxxm
vvvvvllxxx
2
aacb
aaac
2
aacab
aaaca
InputCopy OutputCopy
题目信息
题号
2164D
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟
字符串
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。