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. 《操作系统真象还原》MBR

    以下是读本书第三章的收获. 如何知道一个源程序的各符号(指令和变量)地址?简单来说,地址就是该符号偏移文件开头的距离,符号的地址是按顺序编排的,所以两个相邻的符号,其地址也是相邻的.对于指令来说,指令 ...

  2. Easy_language

    http://www.guosen.com.cn/gxzq/tradestation/help/operate/operate06.html power language https://seekin ...

  3. mysql 基础sql语法总结(一)DDL

    mysql数据库: SQL数据库语言可分为四部分: 1.DDL:对数据库或表的进行操作结构操作 2.DML:对表的记录进行更新(增.删.改)* 3.DQL:对表的内容进行查询 **(重难点) 4.DC ...

  4. C++野指针的存在方式和误区

    1. char* x;这样的一定是野指针,指针声明时要直接初始化!或者置null也行! 2. int main() { char *x=new char; delete x; cout<< ...

  5. HBase Hive

    Hbase数据管理 Hbase就是Hadoop database Hbase是列式数据库 因此Hbase特别适合寻找按照时间排序寻找Top n的场景 Hive数据管理 基于 Hadoop 文件系统的数 ...

  6. C# LINQ学习笔记二:LINQ标准查询操作概述

    本笔记摘抄自:https://www.cnblogs.com/liqingwen/p/5801249.html,记录一下学习过程以备后续查用. “标准查询运算符”是组成语言集成查询 (LINQ) 模式 ...

  7. 0002 Django工程创建

    1 创建一个目录,用于专门存放Django工程的虚拟环境 PyCharm默认虚拟环境在工程内,从而导致打包的时候,会把虚拟环境一起打包. 同时,虚拟环境中的插件较多,一个工程创建了一个虚拟环境,以后, ...

  8. Win10安装2 —— 版本的选择与下载

    本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/xuexianqi/p/12368795.html 一:各个版本的区别 1.Windows10 Home(家 ...

  9. Wannafly Camp 2020 Day 5A Alternative Accounts

    There are n different accounts on the website, and some of them competed in the recent k contests. H ...

  10. 启动Hive时报错(com.mysql.jdbc.Driver") was not found in the CLASSPATH)

    这是因为没有mysql-connector的jar包.需要把jar包复制到hive目录lib文件夹中. 参考博客:https://blog.csdn.net/Realoyou/article/deta ...