AtCoder Regular Contest 170
A
Yet Another AB Problem
AtCoder
⌀ 750
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given two strings $S$ and $T$ of length $N$ consisting of A and B. Let $S_i$ denote the $i$-th character from the left of $S$.

翻译中…

You can repeat the following operation any number of times, possibly zero:

翻译中…
  • Choose integers $i$ and $j$ such that $1\leq i < j \leq N$. Replace $S_i$ with A and $S_j$ with B.
翻译中…

Determine if it is possible to make $S$ equal $T$. If it is possible, find the minimum number of operations required.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2 \times 10^5$
  • Each of $S$ and $T$ is a string of length $N$ consisting of A and B.
  • All input numbers are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
S
T

翻译中…

Output

翻译中…

If it is impossible to make $S$ equal $T$, print -1.

翻译中…

Otherwise, print the minimum number of operations required to do so.

翻译中…

样例

Input #1
5
BAABA
AABAB
Output #1
2
Performing the operation with $i=1$ and $j=3$ changes $S$ to `AABBA`. Performing the operation with $i=4$ and $j=5$ changes $S$ to `AABAB`. Thus, you can make $S$ equal $T$ with two operations. It can be proved that this is the minimum number of operations required, so the answer is $2$.
Input #2
2
AB
BA
Output #2
-1
It can be proved that no matter how many operations you perform, you cannot make $S$ equal $T$.
题目信息
题号
arc170_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。