CF2196E1.Fuzzy Concatenation (Easy Version)

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, n≤105,m≤104n \le 10^{5}, m \le 10^{4}. You can hack only if you solved all versions of this problem.

There are two strings ss and tt, both consisting of lowercase Latin letters. You also have an empty string pp.

You can perform the following operation, which consists of several stages:

  • choose any two integers ll and rr (1≤l≤r≤∣s∣1 \le l \le r \le |s|);
  • copy the substring sl,…,srs_{l},\ldots, s_{r} and append it to the end of string pp;
  • among the last r−l+1r - l + 1 characters of string pp, change at most one character to any lowercase Latin letter.

For example, if the string $s = $ "dhhtyhwbsl" and $p = $ "", you can choose l=3,r=6l = 3, r = 6 and add "htyh" to the end of pp, and then change the character "y" to "a", resulting in $p = $ "htah".

Your task is to determine the minimum number of operations required for string pp to become equal to tt.

这是该问题的简单版本。两个版本的区别在于,在此版本中,n≤105,m≤104n \le 10^{5}, m \le 10^{4}。仅当您已解决该问题的所有版本时,才可进行 hack。

给定两个字符串 ss 和 tt,二者均由小写拉丁字母组成。此外,您还有一个空字符串 pp。

您可以执行以下操作(该操作包含若干阶段):

  • 任选两个整数 ll 和 rr(满足 1≤l≤r≤∣s∣1 \le l \le r \le |s|);
  • 复制子串 sl,…,srs_{l},\ldots, s_{r},并将其追加到字符串 pp 的末尾;
  • 在字符串 pp 的最后 r−l+1r - l + 1 个字符中,至多将其中一个字符修改为任意一个小写拉丁字母。

例如,若字符串 $s = $ "dhhtyhwbsl" 且 $p = $ "",您可以选择 l=3,r=6l = 3, r = 6,将 "htyh" 追加到 pp 末尾,然后将其中的字符 "y" 修改为 "a",从而得到 $p = $ "htah"。

您的任务是确定使字符串 pp 变为与 tt 相等所需的最少操作次数。

输入格式

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

The first line of each test case contains two integers nn and mm (1≤n≤1051 \le n \le 10^{5}, 1≤m≤1041 \le m \le 10^{4}) — the lengths of strings ss and tt.

The second line of each test case contains the string ss of length nn, consisting of lowercase Latin letters.

The third line of each test case contains the string tt of length mm, consisting of lowercase Latin letters.

It is guaranteed that the sum of nn across all test cases does not exceed 10510^{5}, and the sum of mm across all test cases does not exceed 10410^{4}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1051 \le n \le 10^{5},1≤m≤1041 \le m \le 10^{4})—— 分别表示字符串 ss 和 tt 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,由小写拉丁字母组成。

每个测试用例的第三行包含一个长度为 mm 的字符串 tt,由小写拉丁字母组成。

保证所有测试用例中 nn 的总和不超过 10510^{5},且所有测试用例中 mm 的总和不超过 10410^{4}。

输出格式

For each test case, output a single integer — the answer to the problem.

对于每个测试用例,输出一个整数——即该问题的答案。

输入输出样例

  • 输入#1

    4
    1 1
    a
    b
    5 5
    aaaaa
    abzba
    10 13
    dhhtyhwbsl
    htahbsehtyhzb
    7 2
    contest
    on

    输出#1

    1
    3
    3
    1

说明/提示

In the first test case, you can take the substring «a»«\mathtt{a}» from the string ss, change a single letter in this string to «b»«\mathtt{b}», and append it to the end of the string pp, resulting in pp becoming equal to tt.

In the second test case, tt can be obtained in 33 operations as follows:

«mathttacolorredb»+«mathttcolorredz»+«mathttcolorredba»«\\mathtt{a\\color{red}{b}}» + «\\mathtt{\\color{red}{z}}» + «\\mathtt{\\color{red}{b}a}»

The modified characters are highlighted in red.

In the third test case, the string tt can be obtained as follows:

«mathtthtcolorredah»+«mathttbscolorrede»+«mathtthtyhcolorredzb»«\\mathtt{ht\\color{red}{a}h}» + «\\mathtt{bs\\color{red}{e}}» + «\\mathtt{htyh\\color{red}{z}b}»

在第一个测试用例中,你可以从字符串 ss 中取出子串 «a»«\mathtt{a}»,将该子串中的一个字母修改为 «b»«\mathtt{b}»,然后将其追加到字符串 pp 的末尾,从而使 pp 变为 tt。

在第二个测试用例中,tt 可通过 33 次操作得到,如下所示:

«ab»+«z»+«ba»«\mathtt{a\color{red}{b}}» + «\mathtt{\color{red}{z}}» + «\mathtt{\color{red}{b}a}»

被修改的字符以红色高亮显示。

在第三个测试用例中,字符串 tt 可按如下方式得到:

«htah»+«bse»+«htyhzb»«\mathtt{ht\color{red}{a}h}» + «\mathtt{bs\color{red}{e}}» + «\mathtt{htyh\color{red}{z}b}»

输入解题思路,AI测评打分。不知道怎么写?

首页