CF1006D.Two Strings Swaps

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two strings aa and bb consisting of lowercase English letters, both of length nn. The characters of both strings have indices from 11 to nn, inclusive.

You are allowed to do the following changes:

  • Choose any index ii (1≤i≤n1 \le i \le n) and swap characters aia_i and bib_i;
  • Choose any index ii (1≤i≤n1 \le i \le n) and swap characters aia_i and an−i+1a_{n - i + 1};
  • Choose any index ii (1≤i≤n1 \le i \le n) and swap characters bib_i and bn−i+1b_{n - i + 1}.

Note that if nn is odd, you are formally allowed to swap a⌈n2⌉a_{\lceil\frac{n}{2}\rceil} with a⌈n2⌉a_{\lceil\frac{n}{2}\rceil} (and the same with the string bb) but this move is useless. Also you can swap two equal characters but this operation is useless as well.

You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.

In one preprocess move you can replace a character in aa with another character. In other words, in a single preprocess move you can choose any index ii (1≤i≤n1 \le i \le n), any character cc and set ai:=ca_i := c.

Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings aa and bb equal by applying some number of changes described in the list above.

Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string bb or make any preprocess moves after the first change is made.

给你两个由小写英文字母组成的字符串 aa 和 bb,长度均为 nn。两个字符串的字符下标均从 11 到 nn(含端点)。

你可以执行以下任意次数、任意顺序的操作:

  • 选择任意下标 ii(1≤i≤n1 \le i \le n),交换字符 aia_i 和 bib_i;
  • 选择任意下标 ii(1≤i≤n1 \le i \le n),交换字符 aia_i 和 an−i+1a_{n - i + 1};
  • 选择任意下标 ii(1≤i≤n1 \le i \le n),交换字符 bib_i 和 bn−i+1b_{n - i + 1}。

注意:若 nn 为奇数,则形式上允许交换 a⌈n2⌉a_{\lceil\frac{n}{2}\rceil} 与自身(对字符串 bb 同理),但该操作无实际效果。同样地,交换两个相同字符的操作也无实际效果。

你需要通过上述操作使两字符串相等。但显然,仅靠这些交换操作,有时无法使两字符串相等。

在一次预处理操作中,你可以将 aa 中某个字符替换为另一个字符。换言之,一次预处理操作即:选择任意下标 ii(1≤i≤n1 \le i \le n)、任一字符 cc,并令 ai:=ca_i := c。

你的任务是求出所需的最少预处理操作次数,使得在执行这些预处理操作后,能通过若干次上述所列操作使字符串 aa 和 bb 相等。

注意:预处理操作之后所执行的操作次数无关紧要。此外,你不能对字符串 bb 执行预处理操作,也不能在第一次常规操作执行之后再进行任何预处理操作。

输入格式

The first line of the input contains one integer nn (1≤n≤1051 \le n \le 10^5) — the length of strings aa and bb.

The second line contains the string aa consisting of exactly nn lowercase English letters.

The third line contains the string bb consisting of exactly nn lowercase English letters.

输入的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 字符串 aa 和 bb 的长度。

第二行包含字符串 aa,该字符串恰好由 nn 个小写英文字母组成。

第三行包含字符串 bb,该字符串恰好由 nn 个小写英文字母组成。

输出格式

Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string aa equal to string bb with a sequence of changes from the list above.

输出一个整数——在执行上述变换操作之前,需要进行的最少预处理操作次数,使得字符串 aa 能够通过一系列上述列表中的变换操作变为字符串 bb。

输入输出样例

  • 输入#1

    7
    abacaba
    bacabaa

    输出#1

    4
  • 输入#2

    5
    zcabd
    dbacz

    输出#2

    0

说明/提示

In the first example preprocess moves are as follows: $a_1 := $'b', $a_3 := $'c', $a_4 := $'a' and a5:=a_5:='b'. Afterwards, $a = $"bbcabba". Then we can obtain equal strings by the following sequence of changes: swap(a2,b2)swap(a_2, b_2) and swap(a2,a6)swap(a_2, a_6). There is no way to use fewer than 44 preprocess moves before a sequence of changes to make string equal, so the answer in this example is 44.

In the second example no preprocess moves are required. We can use the following sequence of changes to make aa and bb equal: swap(b1,b5)swap(b_1, b_5), swap(a2,a4)swap(a_2, a_4).

在第一个例子中,预处理操作如下:$a_1 := ′b′,'b',a_3 := ′c′,'c',a_4 := $'a',且 a5:=a_5:='b'。之后,$a = "bbcabba"。接着,我们可通过如下交换序列使两字符串相等:"bbcabba"。接着,我们可通过如下交换序列使两字符串相等:swap(a_2, b_2)$ 和 swap(a2,a6)swap(a_2, a_6)。不存在少于 44 次预处理操作的方式,使得在后续一系列交换操作后能使字符串相等,因此本例的答案为 44。

在第二个例子中,无需任何预处理操作。我们可通过如下交换序列使 aa 与 bb 相等:swap(b1,b5)swap(b_1, b_5)、swap(a2,a4)swap(a_2, a_4)。

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

首页