CF1778C.Flexible String

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a string aa and a string bb . Both of the strings have length nn . There are at most 1010 different characters in the string aa . You also have a set QQ . Initially, the set QQ is empty. You can apply the following operation on the string aa any number of times:

  • Choose an index ii ( 1in1\leq i \leq n ) and a lowercase English letter cc . Add aia_i to the set QQ and then replace aia_i with cc .

For example, Let the string aa be " abecca\tt{abecca} ". We can do the following operations:

  • In the first operation, if you choose i=3i = 3 and c=xc = \tt{x} , the character a3=ea_3 = \tt{e} will be added to the set QQ . So, the set QQ will be {e}\{\tt{e}\} , and the string aa will be " abxcca\tt{ab\underline{x}cca} ".
  • In the second operation, if you choose i=6i = 6 and c=sc = \tt{s} , the character a6=aa_6 = \tt{a} will be added to the set QQ . So, the set QQ will be {e,a}\{\tt{e}, \tt{a}\} , and the string aa will be " abxccs\tt{abxcc\underline{s}} ".

You can apply any number of operations on aa , but in the end, the set QQ should contain at most kk different characters. Under this constraint, you have to maximize the number of integer pairs (l,r)(l, r) ( 1lrn1\leq l\leq r \leq n ) such that a[l,r]=b[l,r]a[l,r] = b[l,r] . Here, s[l,r]s[l,r] means the substring of string ss starting at index ll (inclusively) and ending at index rr (inclusively).

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1041 \le t \le 10^4 ). The description of the test cases follows.

The first line contains two integers nn and kk ( 1n1051\leq n \leq 10^5 , 0k100\leq k\leq 10 ) — the length of the two strings and the limit on different characters in the set QQ .

The second line contains the string aa of length nn . There is at most 1010 different characters in the string aa .

The last line contains the string bb of length nn .

Both of the strings aa and bb contain only lowercase English letters. The sum of nn over all test cases doesn't exceed 10510^5 .

输出格式

For each test case, print a single integer in a line, the maximum number of pairs (l,r)(l, r) satisfying the constraints.

输入输出样例

  • 输入#1

    6
    3 1
    abc
    abd
    3 0
    abc
    abd
    3 1
    xbb
    xcd
    4 1
    abcd
    axcb
    3 10
    abc
    abd
    10 3
    lkwhbahuqa
    qoiujoncjb

    输出#1

    6
    3
    6
    6
    6
    11

说明/提示

In the first case, we can select index i=3i = 3 and replace it with character c=dc = \tt{d} . All possible pairs (l,r)(l,r) will be valid.

In the second case, we can't perform any operation. The 33 valid pairs (l,r)(l,r) are:

  1. a[1,1]=b[1,1]=a[1,1] = b[1,1] = " a\tt{a} ",
  2. a[1,2]=b[1,2]=a[1,2] = b[1,2] = " ab\tt{ab} ",
  3. a[2,2]=b[2,2]=a[2,2] = b[2,2] = " b\tt{b} ".

In the third case, we can choose index 22 and index 33 and replace them with the characters c\tt{c} and d\tt{d} respectively. The final set QQ will be {b}\{\tt{b}\} having size 11 that satisfies the value of kk . All possible pairs (l,r)(l,r) will be valid.

首页