题库练习 Game with Reversing
← 上一题 下一题 →

A16066 | Game with Reversing

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Alice and Bob are playing a game. They have two strings $S$ and $T$ of the same length $n$ consisting of lowercase latin letters. Players take turns alternately, with Alice going first.

On her turn, Alice chooses an integer $i$ from $1$ to $n$ , one of the strings $S$ or $T$ , and any lowercase latin letter $c$ , and replaces the $i$ -th symbol in the chosen string with the character $c$ .

On his turn, Bob chooses one of the strings $S$ or $T$ , and reverses it. More formally, Bob makes the replacement $S := \operatorname{rev}(S)$ or $T := \operatorname{rev}(T)$ , where $\operatorname{rev}(P) = P_n P_{n-1} \ldots P_1$ .

The game lasts until the strings $S$ and $T$ are equal. As soon as the strings become equal, the game ends instantly.

Define the duration of the game as the total number of moves made by both players during the game. For example, if Alice made $2$ moves in total, and Bob made $1$ move, then the duration of this game is $3$ .

Alice's goal is to minimize the duration of the game, and Bob's goal is to maximize the duration of the game.

What will be the duration of the game, if both players play optimally? It can be shown that the game will end in a finite number of turns.

输入格式

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

The first line of each test case contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the length of the strings $S$ and $T$ .

The second line of each test case contains a string $S$ of length $n$ consisting of lowercase latin letters.

The third line of each test case contains a string $T$ of length $n$ consisting of lowercase latin letters.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$ .

输出格式

For each test case, output a single number on a separate line — the duration of the described game, if both players play optimally.

输入输出样例

输入 #1
7
5
abcde
abxde
5
hello
olleo
2
ab
cd
7
aaaaaaa
abbbbba
1
q
q
6
yoyoyo
oyoyoy
8
abcdefgh
hguedfbh
输出 #1
1
2
3
9
0
2
6
C++ 编辑器
输入
输出