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
3
100
001
output

Copy
2
input

Copy
4
0101
0011
output

Copy
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.


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

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = 1e5 + ;
const long long inf = 0x7f7f7f7f7f7f7f7f; int main()
{
int n,res=;
cin >> n;
string a, b;
cin >> a >> b;
int ans=;
for (int i = ; i < a.size(); i++)
{
if (a[i] != b[i])
{
if (i + < a.size() && a[i + ] != b[i + ] && a[i]!=a[i+])
{
res++;
i++;
}
else
{
res++;
}
}
}
cout << res;
}

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. c#枚举转字典或表格

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. AMCL论文及源码解析--参数(持续更新中)

    整理内容来自:http://wiki.ros.org/amcl 1.AMCL订阅的节点: scan (sensor_msgs/LaserScan):激光数据 tf (tf/tfMessage):各种转 ...

  3. PCI Express

    1.1课题研究背景 在目前高速发展的计算机平台上,应用软件的开发越来越依赖于硬件平台,尤其是随着大数据.云计算的提出,人们对计算机在各个领域的性能有更高的需求.日常生活中的视频和图像信息包含大量的数据 ...

  4. Windows Live Writer 2012 安装配置

    Windows Live Writer 2012用起来比较舒服,可以直接编辑 在线博客文章 下载地址 http://g.live.com/1rewlive5-all/zh-cn/wlsetup-all ...

  5. LaTeX技巧009:中国象棋的LaTeX排版

    Latex可以排版容易排版中国象棋, 围棋, 国际象棋棋谱和乐谱, 详情请见. http://bbs.chinatex.org/forum.php?mod=viewthread&tid=498 ...

  6. 软件架构期末复习(Struts2+Spring+Hibernate)

    Struts2+Spring+Hibernate The Model-ViewController pattern in Struts2 is implemented with the followi ...

  7. laravel的Validation检索验证错误消息

    基本用法 处理错误消息 错误消息和视图 可用的验证规则 有条件地添加规则 自定义错误消息 自定义验证规则 基本用法 Laravel提供了一个简单.方便的工具,用于验证数据并通过validation类检 ...

  8. eclipse下载更新可用的SDK 2018-11-12

    懒人方法: mirrors.neusoft.edu.cn:80 操作步骤: 1. Android SDK Manager----Tools----Options-----Http Proxy Serv ...

  9. Atom 基础使用

    当你安装好了 Atom 之后,让我们来认识一下它吧. 当你第一次打开 Atom 的时候,你会看到这样的一个窗口:   这是 Atom 的欢迎屏幕(welcome screen),它展示了一些不错的建议 ...

  10. PHP 中 16 个魔术方法详解

    PHP 中 16 个魔术方法详解   前言 PHP中把以两个下划线__开头的方法称为魔术方法(Magic methods),这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __constru ...