

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
個の文字列 が与えられます。各文字列は英小文字からなります。
に対し以下の問題を解いてください。
として、 に対して以下の 種類の操作を好きな順番で好きな回数繰り返すことを考える。
- コストを 払い、 の末尾の文字を削除する。この操作は が空文字列でない時に可能である。
- コストを 払い、 の末尾に好きな英小文字を追加する。
を空文字列、 のいずれかと一致させるために払うコストの総和の最小値を求めよ。
制約
- は英小文字からなる長さ 以上の文字列
入力
入力は以下の形式で標準入力から与えられる。
出力
行出力せよ。 行目 には に対する答えを出力せよ。
入力例 1Copy
3 snuke snuki snuuk
出力例 1Copy
5 2 4
の場合は末尾の文字を削除する操作を 回行うことで空文字列にすることができます。
の場合は末尾の文字を削除した後に末尾に e
を追加することで と一致させることができます。
の場合は末尾の文字を 回削除した後末尾に k
を追加し、末尾に i
を追加することで と一致させることができます。
入力例 2Copy
3 abc arc agc
出力例 2Copy
3 3 3
入力例 3Copy
8 at atatat attat aatatatt attattat ttatta tta tt
出力例 3Copy
2 4 3 8 3 6 3 1
Score : points
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 1Copy
3 snuke snuki snuuk
Sample Output 1Copy
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 2Copy
3 abc arc agc
Sample Output 2Copy
3 3 3
Sample Input 3Copy
8 at atatat attat aatatatt attattat ttatta tta tt
Sample Output 3Copy
2 4 3 8 3 6 3 1