#abc377g. G - Edit to Match
G - Edit to Match
Score : points
问题陈述
你给定了 个字符串 。每个字符串由小写英文字母组成。
对于每个 ,解决以下问题。
设 并考虑执行以下两种类型的操作任意次数,以任意顺序:
- 支付 的成本删除 的最后一个字符。当 不为空时,此操作是可能的。
- 支付 的成本在 的末尾添加任何小写英文字母。
找出使 要么变为空字符串,要么与 中的一个匹配所需的最小总成本。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given strings . Each string consists of lowercase English letters.
For each , solve the following problem.
Let and consider performing the following two types of operations any number of times in any order:
- Pay a cost of to delete the last character of . This operation is possible when is not empty.
- Pay a cost of to add any lowercase English letter to the end of .
Find the minimum total cost needed to make either empty or match one of .
Constraints
- Each is a string of length at least consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer for .
Sample Input 1
3
snuke
snuki
snuuk
Sample Output 1
5
2
4
For , you can make empty by performing the delete operation five times.
For , you can make match by deleting the last character and then adding e
to the end.
For , you can make match by deleting the last character twice, then adding k
to the end, and finally adding i
to the end.
Sample Input 2
3
abc
arc
agc
Sample Output 2
3
3
3
Sample Input 3
8
at
atatat
attat
aatatatt
attattat
ttatta
tta
tt
Sample Output 3
2
4
3
8
3
6
3
1