CF1037C.Equalize

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two binary strings aa and bb of the same length. You can perform the following two operations on the string aa :

  • Swap any two bits at indices ii and jj respectively ( 1i,jn1 \le i, j \le n ), the cost of this operation is ij|i - j| , that is, the absolute difference between ii and jj .
  • Select any arbitrary index ii ( 1in1 \le i \le n ) and flip (change 00 to 11 or 11 to 00 ) the bit at this index. The cost of this operation is 11 .

Find the minimum cost to make the string aa equal to bb . It is not allowed to modify string bb .

输入格式

The first line contains a single integer nn ( 1n1061 \le n \le 10^6 ) — the length of the strings aa and bb .

The second and third lines contain strings aa and bb respectively.

Both strings aa and bb have length nn and contain only '0' and '1'.

输出格式

Output the minimum cost to make the string aa equal to bb .

输入输出样例

  • 输入#1

    3
    100
    001
    

    输出#1

    2
    
  • 输入#2

    4
    0101
    0011
    

    输出#2

    1
    

说明/提示

In the first example, one of the optimal solutions is to flip index 11 and index 33 , the string aa changes in the following way: "100" \to "000" \to "001". The cost is 1+1=21 + 1 = 2 .

The other optimal solution is to swap bits and indices 11 and 33 , the string aa changes then "100" \to "001", the cost is also 13=2|1 - 3| = 2 .

In the second example, the optimal solution is to swap bits at indices 22 and 33 , the string aa changes as "0101" \to "0011". The cost is 23=1|2 - 3| = 1 .

首页