AtCoder Grand Contest 049
翻译中…
Problem Statement
翻译中…
Given are length-$N$ strings $S$ and $T$ consisting of 0 and 1. You can do the following operation on $S$ any number of times:
翻译中…
- Choose
$i$($2 \leq i \leq N$) such that$S_i=$1, and replace$S_i$with0. Additionally, invert$S_{i-1}$, that is, change it to1if it is0now and vice versa.
翻译中…
Is it possible to make $S$ exactly match $T$? If it is possible, how many operations does it take at least?
翻译中…
Constraints
翻译中…
$1 \leq N \leq 5 \times 10^5$$S$is a string of length$N$consisting of0and1.$T$is a string of length$N$consisting of0and1.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
S
T
翻译中…
Output
翻译中…
If it is possible to make $S$ exactly match $T$, print the minimum number of operations it takes. Otherwise, print $-1$.
翻译中…
样例
Input #1
3
001
100
Output #1
2
We can do as follows: `001` → (choose $i=3$) → `010` → (choose $i=2$) → `100`.
Input #2
3
001
110
Output #2
-1
Input #3
5
10111
01010
Output #3
5
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。