#P6793. [SNOI2020] 字符串
[SNOI2020] 字符串
Problem Description
There are two strings of length consisting of lowercase letters. Take all their substrings of length (each has substrings). These substrings form multisets , respectively. Now you need to modify the strings in so that and become exactly the same.
You may perform the following operation any number of times: choose one string in and modify a suffix of this string. The cost of this operation is the length of the chosen suffix. The total cost is the sum of the costs of all operations. Find the minimum possible total cost.
Input Format
The first line contains two integers , representing the string length and the substring length.
The second line contains a lowercase string .
The third line contains a lowercase string .
Output Format
Output one integer in one line, representing the minimum total cost.
5 3
aabaa
ababa
3
Hint
Sample Explanation
For sample , all substrings are: , . You can see that there is one pair of identical substrings . For the remaining ones, change to (cost ), and change to (cost ). The total cost is .
Constraints
For all testdata, .
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, each character of the strings is uniformly random among lowercase letters.
- For the remaining of the testdata, there are no special restrictions.
Input Format
Output Format
Hint
Translated by ChatGPT 5