No.2018 X-Y-X
タグ : / 解いたユーザー数 75
作問者 :
milkcoffee
/ テスター :
Kiri8128
Problem Statement
You are given strings $S$ and $T$ of length $N$ consisting of A and B. You may perform the following operation on the string $S$ any number of times, possibly $0$.
- Choose $1 \leq i \leq N-2$ such that $S_i = S_{i+2}$. Then, change the character $S_{i+1}$ (
AbecomesB, andBbecomesA).
Can you make $S$ equal to $T$? If so, find the minimum number of operations required.
Input
$N$ $S$ $T$
- $3 \leq N \leq 2 \times 10^5$
- $N$ is an integer.
- $S,T$ are strings of length $N$ consisting of
A,B.
Output
If $S$ can be made equal to $T$, print the minimum number of operations required.
If it is impossible to make them equal, print -1.
Sample
Sample 1
Input
4 ABAA AABA
Output
2
First, performing the operation with $i=1$ makes $S$ become AAAA.
Next, performing the operation with $i=2$ makes $S$ become AABA.
Sample 2
Input
4 BBAA BABA
Output
-1
Since no operation can be performed on $S$, $S$ cannot be made equal to $T$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。