問題一覧 > 通常問題

No.2018 X-Y-X

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 75
作問者 : milkcoffee / テスター : Kiri8128
お気に入りにしたユーザー ProblemId : 8006 / 自分の提出
問題文最終更新日: 2022-07-06 16:19:30
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 353 (オムニバス) (順位表) の他の問題:

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}$ (A becomes B, and B becomes A).

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もしくは右上の雲マークをクリックしてアカウントを作成してください。