Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
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 < 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 . 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. 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. 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$ |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
347802729 |
ksandr1v |
D |
Nov. 6, 2025, 10:37 p.m. |
OK |
C# 13 |
TESTS |
13 |
796 |
37785600 |
|
|
|
347821547 |
naiij |
D |
Nov. 7, 2025, 4:01 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
46 |
102400 |
|
|
|
347820254 |
simplyjoke |
D |
Nov. 7, 2025, 3:43 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
61 |
0 |
|
|
|
347781924 |
wthdouwant |
D |
Nov. 6, 2025, 6:27 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
61 |
0 |
|
|
|
347767074 |
mukhin_kostya |
D |
Nov. 6, 2025, 5:03 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
61 |
0 |
|
|
|
347769396 |
explorerxx |
D |
Nov. 6, 2025, 5:10 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
61 |
4096000 |
|
|
|
347805433 |
haha1324 |
D |
Nov. 6, 2025, 11:50 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
61 |
16179200 |
|
|
|
347825198 |
gojoestar |
D |
Nov. 7, 2025, 4:51 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
62 |
0 |
|
|
|
347794545 |
FliccEatsPizza |
D |
Nov. 6, 2025, 8:28 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
62 |
0 |
|
|
|
347787661 |
atam.damir |
D |
Nov. 6, 2025, 7:16 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
62 |
2150400 |
|
|
|
347776792 |
Harsh2005 |
D |
Nov. 6, 2025, 5:33 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
13 |
62 |
2150400 |
|
|
|
347811708 |
sakuaika |
D |
Nov. 7, 2025, 1:58 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
46 |
9011200 |
|
|
|
347825969 |
TianTianChaoFangDe |
D |
Nov. 7, 2025, 5:01 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
46 |
15052800 |
|
|
|
347811555 |
FlowerandYou |
D |
Nov. 7, 2025, 1:55 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
1945600 |
|
|
|
347788079 |
whomadewho |
D |
Nov. 6, 2025, 7:20 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
2969600 |
|
|
|
347792015 |
gakshat468 |
D |
Nov. 6, 2025, 7:59 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
5017600 |
|
|
|
347782087 |
Pranav_19111 |
D |
Nov. 6, 2025, 6:28 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
5939200 |
|
|
|
347769011 |
kevin20012 |
D |
Nov. 6, 2025, 5:09 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
6451200 |
|
|
|
347809606 |
bachbeo2007 |
D |
Nov. 7, 2025, 1:22 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
9011200 |
|
|
|
347828336 |
Watarai |
D |
Nov. 7, 2025, 5:31 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
10035200 |
|
|
|
347805559 |
enze_qwq |
D |
Nov. 6, 2025, 11:54 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
13 |
61 |
10035200 |
|
|
|
347826528 |
WhiteBread |
D |
Nov. 7, 2025, 5:08 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
1536000 |
|
|
|
347782887 |
Mr.Smoothy |
D |
Nov. 6, 2025, 6:34 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
1638400 |
|
|
|
347809155 |
j30 |
D |
Nov. 7, 2025, 1:14 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
2560000 |
|
|
|
347807728 |
ddbjiang |
D |
Nov. 7, 2025, 12:47 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
2560000 |
|
|
|
347819428 |
cyu17 |
D |
Nov. 7, 2025, 3:31 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
4608000 |
|
|
|
347782860 |
Ravindra_Rinwa |
D |
Nov. 6, 2025, 6:34 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
5632000 |
|
|
|
347782945 |
thewoahguy24 |
D |
Nov. 6, 2025, 6:35 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
9625600 |
|
|
|
347828110 |
Vcoistnt |
D |
Nov. 7, 2025, 5:28 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
16588800 |
|
|
|
347830679 |
ryanyuanyourui |
D |
Nov. 7, 2025, 5:58 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
17100800 |
|
|
|
347773017 |
ayushdevani01 |
D |
Nov. 6, 2025, 5:21 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
13 |
46 |
17612800 |
|
|
|
347775151 |
zap4eg |
D |
Nov. 6, 2025, 5:28 p.m. |
OK |
Go |
TESTS |
13 |
77 |
6553600 |
|
|
|
347775442 |
Burhan_Akkus |
D |
Nov. 6, 2025, 5:29 p.m. |
OK |
Java 21 |
TESTS |
13 |
359 |
921600 |
|
|
|
347763319 |
pscrwh |
D |
Nov. 6, 2025, 4:51 p.m. |
OK |
Java 21 |
TESTS |
13 |
390 |
5120000 |
|
|
|
347766985 |
lyongwolf |
D |
Nov. 6, 2025, 5:02 p.m. |
OK |
Java 21 |
TESTS |
13 |
593 |
43212800 |
|
|
|
347763209 |
BiggestFish06 |
D |
Nov. 6, 2025, 4:51 p.m. |
OK |
Java 21 |
TESTS |
13 |
733 |
68300800 |
|
|
|
347782645 |
akshatjai258 |
D |
Nov. 6, 2025, 6:33 p.m. |
OK |
Java 21 |
TESTS |
13 |
1233 |
154316800 |
|
|
|
347764935 |
bhaskar_aa45 |
D |
Nov. 6, 2025, 4:56 p.m. |
OK |
Java 21 |
TESTS |
13 |
1358 |
47820800 |
|
|
|
347771972 |
nikhilsingh_21 |
D |
Nov. 6, 2025, 5:18 p.m. |
OK |
Java 21 |
TESTS |
13 |
1639 |
29081600 |
|
|
|
347819125 |
parad512 |
D |
Nov. 7, 2025, 3:27 a.m. |
OK |
Java 21 |
TESTS |
13 |
1780 |
261222400 |
|
|
|
347781997 |
SoMeQuit |
D |
Nov. 6, 2025, 6:28 p.m. |
OK |
Java 8 |
TESTS |
13 |
328 |
36147200 |
|
|
|
347793667 |
34z12000 |
D |
Nov. 6, 2025, 8:17 p.m. |
OK |
PyPy 3 |
TESTS |
13 |
1468 |
212787200 |
|
|
|
347827948 |
jjik |
D |
Nov. 7, 2025, 5:26 a.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
187 |
26726400 |
|
|
|
347800099 |
explainer |
D |
Nov. 6, 2025, 9:45 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
249 |
70451200 |
|
|
|
347799093 |
lol555 |
D |
Nov. 6, 2025, 9:28 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
265 |
71987200 |
|
|
|
347781968 |
LightHouse1 |
D |
Nov. 6, 2025, 6:28 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
281 |
89600000 |
|
|
|
347777256 |
nitish_biswas01 |
D |
Nov. 6, 2025, 5:34 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
296 |
83660800 |
|
|
|
347803281 |
czjnbb |
D |
Nov. 6, 2025, 10:52 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
358 |
72396800 |
|
|
|
347770125 |
MyTreeBala |
D |
Nov. 6, 2025, 5:12 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
358 |
79360000 |
|
|
|
347782356 |
helltractor |
D |
Nov. 6, 2025, 6:31 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
358 |
120217600 |
|
|
|
347774100 |
skyoceanland |
D |
Nov. 6, 2025, 5:24 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
421 |
120217600 |
|
|
|
347768281 |
ossau |
D |
Nov. 6, 2025, 5:06 p.m. |
OK |
PyPy 3-64 |
TESTS |
13 |
437 |
124313600 |
|
|
|
347769353 |
Jimanbanashi |
D |
Nov. 6, 2025, 5:10 p.m. |
OK |
Python 2 |
TESTS |
13 |
999 |
56422400 |
|
|
|
347830905 |
peter5264 |
D |
Nov. 7, 2025, 6 a.m. |
OK |
Python 3 |
TESTS |
13 |
343 |
27648000 |
|
|
|
347764233 |
jpg.stdstd |
D |
Nov. 6, 2025, 4:54 p.m. |
OK |
Python 3 |
TESTS |
13 |
562 |
44032000 |
|
|
|
347799067 |
lol555 |
D |
Nov. 6, 2025, 9:28 p.m. |
OK |
Python 3 |
TESTS |
13 |
1046 |
44441600 |
|
|
|
347764522 |
Egor_Shchetinin |
D |
Nov. 6, 2025, 4:55 p.m. |
OK |
Python 3 |
TESTS |
13 |
1171 |
149094400 |
|
|
|
347764763 |
WiredMind |
D |
Nov. 6, 2025, 4:55 p.m. |
OK |
Python 3 |
TESTS |
13 |
1437 |
224153600 |
|
|
|
347770237 |
RanjanV_1 |
D |
Nov. 6, 2025, 5:12 p.m. |
OK |
Rust 2024 |
TESTS |
13 |
1265 |
34099200 |
|
|
remove filters
Back to search problems