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 (1≤i,j≤n1≤i,j≤n), the cost of this operation is |i−j||i−j|, that is, the absolute difference between ii and jj.
  • Select any arbitrary index ii (1≤i≤n1≤i≤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.

Input

The first line contains a single integer nn (1≤n≤1061≤n≤106) — 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

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

Examples
input

Copy
  1. 3
    100
    001
output

Copy
  1. 2
input

Copy
  1. 4
    0101
    0011
output

Copy
  1. 1
Note

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" →→ "000" →→ "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" →→ "001", the cost is also |1−3|=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" →→ "0011". The cost is |2−3|=1|2−3|=1.


还是太直线思维了,老是想着用哪个减哪个,就没想到让答案一直增加:(

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <set>
  6. #include <queue>
  7. #include <map>
  8. #include <sstream>
  9. #include <cstdio>
  10. #include <cstring>
  11. #include <numeric>
  12. #include <cmath>
  13. #include <unordered_set>
  14. #include <unordered_map>
  15. #include <xfunctional>
  16. #define ll long long
  17. #define mod 998244353
  18. using namespace std;
  19. int dir[][] = { {,},{,-},{-,},{,} };
  20. const int maxn = 1e5 + ;
  21. const long long inf = 0x7f7f7f7f7f7f7f7f;
  22.  
  23. int main()
  24. {
  25. int n,res=;
  26. cin >> n;
  27. string a, b;
  28. cin >> a >> b;
  29. int ans=;
  30. for (int i = ; i < a.size(); i++)
  31. {
  32. if (a[i] != b[i])
  33. {
  34. if (i + < a.size() && a[i + ] != b[i + ] && a[i]!=a[i+])
  35. {
  36. res++;
  37. i++;
  38. }
  39. else
  40. {
  41. res++;
  42. }
  43. }
  44. }
  45. cout << res;
  46. }

Equalize的更多相关文章

  1. D. Equalize Them All Codeforces Round #550 (Div. 3)

    D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. Codeforces 999D Equalize the Remainders (set使用)

    题目连接:Equalize the Remainders 题意:n个数字,对m取余有m种情况,使得每种情况的个数都为n/m个(保证n%m=0),最少需要操作多少次? 每次操作可以把某个数字+1.输出最 ...

  3. 1037C_ Equalize(字符串)

    modify 改变 C. Equalize time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. D. Equalize the Remainders (set的基本操作)

    D. Equalize the Remainders time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  5. (原创)Codeforces Round #550 (Div. 3) D. Equalize Them All

    D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces1144D(D题)Equalize Them All

    D. Equalize Them All You are given an array aa consisting of nn integers. You can perform the follow ...

  7. CF1234A Equalize Prices

    洛谷 CF1234A Equalize Prices Again 洛谷传送门 题目描述 You are both a shop keeper and a shop assistant at a sma ...

  8. D. Equalize the Remainders set的使用+思维

    D. Equalize the Remainders set的学习::https://blog.csdn.net/byn12345/article/details/79523516 注意set的end ...

  9. D. Equalize the Remainders 解析(思維)

    Codeforce 999 D. Equalize the Remainders 解析(思維) 今天我們來看看CF999D 題目連結 題目 略,請直接看原題 前言 感覺要搞個類似\(stack\)的東 ...

  10. Codeforces 1037C Equalize

    原题 题目大意: 给你两个长度都为\(n\)的的\(01\)串\(a,b\),现在你可以对\(a\)串进行如下两种操作: 1.交换位置\(i\)和位置\(j\),代价为\(|i-j|\) 2.反转位置 ...

随机推荐

  1. python三器

    1.1 装饰器 1.装饰器的作用 1. 装饰器作用:本质是函数(装饰其他函数)就是为其他函数添加其他功能 2. 装饰器必须准寻得原则: 1)不能修改被装饰函数的源代码 2)不能修改被装饰函数的调用方式 ...

  2. pandas 将多个dataframe保存为一个excel文件的多个sheet表中

    # 创建文件 def create(): df1 = pd.DataFrame({"a1": [1, 2, 3], "b1": [4, 5, 6]}) df2 ...

  3. AI 所需的数学基础

    一.[微积分] 基础概念(极限.可微与可导.全导数与偏导数):只要学微积分,就必须要明白的概念,否则后面什么都无法继续学习. 函数求导:求导是梯度的基础,而梯度是 AI 算法的基础,因此求导非常重要! ...

  4. 0级搭建类007-Ubuntu Desktop Linux安装 (18.04.2) 公开

    项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...

  5. Life Forms[poj3294]题解

    Life Forms Description - You may have wondered why most extraterrestrial life forms resemble humans, ...

  6. java学习笔记之IO编程—内存流、管道流、随机流

    1.内存操作流 之前学习的IO操作输入和输出都是从文件中来的,当然,也可以将输入和输出的位置设置在内存上,这就需要用到内存操作流,java提供两类内存操作流 字节内存操作流:ByteArrayOutp ...

  7. 关于docker容器访问的主机的端口问题

    docker容器需要访问主机的,不能使用127.0.0.1,127.0.0.1访问的是docker容器不是主机: docker容器创建时会分配一个主机ip,可在主机使用命令 docker inspec ...

  8. Spark学习之路 (一)Spark初识 [转]

    官网介绍 什么是Spark 官网地址:http://spark.apache.org/ Apache Spark™是用于大规模数据处理的统一分析引擎. 从右侧最后一条新闻看,Spark也用于AI人工智 ...

  9. python接口

    用正则表达式提取数据: https://www.cnblogs.com/dwdw/p/9553192.html python unittest TestCase间共享数据(全局变量的使用): http ...

  10. [TJOI2007] 路标设置 - 二分答案,贪心

    考虑到答案满足可二分性,段内可以贪心,所以暴力二分即可 注意-1 详见代码(我这题都能写WA) #include <bits/stdc++.h> using namespace std; ...