QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 256 MB 満点: 100

#6572. 编辑

統計

Bajtazar 将他 $n$ 位的网上银行密码保存在一个名为 haslo.txt 的文本文件中。在听到窗外传来“我们的钱不安全!”的呼喊声后,他决定谨慎地修改这个已经很旧的密码。于是,Bajtazar 想出了一个新的 $n$ 位密码。为了不忘记它,他只需要修改密码文件的内容即可。

Bajtazar 电脑上安装的文本编辑器允许对文件内容执行两种类型的操作:

(1) 修改文件中第 $i$ 位($1 \le i \le n$)的字符。 (2) 将文件中所有出现的某个特定字符 $x$ 替换为另一个字符 $y$(其中 $x, y \in \{\text{a, b, \dots, z}\}$)。

执行第 (1) 类操作需要 Bajtazar 1 秒钟。第 (2) 类操作需要按下复杂的组合键,因此无论选择哪种字符 $x$ 和 $y$,都需要 Bajtazar 花费 $c$ 秒钟。操作是逐个执行的,且每次操作都会作用于之前所有操作执行后的文件内容。

Bajtazar 想知道他最快能在多少秒内完成对 haslo.txt 文件的编辑。

输入格式

输入的第一行包含两个整数 $n$ 和 $c$($1 \le c \le n \le 1\,000\,000$),分别表示密码的长度和执行第 (2) 类操作所需的秒数。第二行和第三行分别包含表示 Bajtazar 旧密码和新密码的字符串。密码由 $n$ 个小写英文字母(a-z)组成,且两个密码不相同。

输出格式

在输出的唯一一行中,输出 Bajtazar 使用第 (1) 类或第 (2) 类操作完成文件编辑所需的最少秒数。

样例

输入 1

5 2
aaabc
bbbaa

输出 1

4

说明 1

可以将位置 1、2 和 3 上的字符通过一次第 (2) 类操作修改为正确字符。位置 4 和 5 上的字符通过两次第 (1) 类操作进行修改。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.