#P6793. [SNOI2020] 字符串

    ID: 7439 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串2020各省省选后缀自动机 SAM树形 DP后缀数组 SA

[SNOI2020] 字符串

Problem Description

There are two strings a,ba, b of length nn consisting of lowercase letters. Take all their substrings of length kk (each has nk+1n - k + 1 substrings). These substrings form multisets A,BA, B, respectively. Now you need to modify the strings in AA so that AA and BB become exactly the same.

You may perform the following operation any number of times: choose one string in AA 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 n,kn, k, representing the string length and the substring length.
The second line contains a lowercase string aa.
The third line contains a lowercase string bb.

Output Format

Output one integer in one line, representing the minimum total cost.

5 3
aabaa
ababa
3

Hint

Sample Explanation

For sample 11, all substrings are: A={aab,aba,baa}A = \{aab, aba, baa\}, B={aba,bab,aba}B = \{aba, bab, aba\}. You can see that there is one pair of identical substrings abaaba. For the remaining ones, change aabaab to abaaba (cost 22), and change baabaa to babbab (cost 11). The total cost is 33.

Constraints

For all testdata, 1kn1.5×1051 \le k \le n \le 1.5 \times 10^5.

  • For 10%10\% of the testdata, n11n \le 11.
  • For another 20%20\% of the testdata, n200n \le 200.
  • For another 20%20\% of the testdata, n2000n \le 2000.
  • For another 10%10\% of the testdata, each character of the strings is uniformly random among lowercase letters.
  • For the remaining 40%40\% of the testdata, there are no special restrictions.

Input Format

Output Format

Hint

Translated by ChatGPT 5