AtCoder Grand Contest 049
B
Flip Digits
AtCoder
⌀ 1171
原题
← AC →
翻译中…

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$ with 0. Additionally, invert $S_{i-1}$, that is, change it to 1 if it is 0 now 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 of 0 and 1.
  • $T$ is a string of length $N$ consisting of 0 and 1.
翻译中…

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
题目信息
题号
agc049_b
时间限制
2 s
内存限制
1024 MB

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