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. 【剑指Offer】01、二维数组中的查找

    题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...

  2. 树莓派查看ip地址(命令ifconfig)和退出ping

    1.1树莓派查看ip地址用如下命令: ifconfig -a 结果如下图所示: 注意:树莓派查看ip地址是用命令ifconfig,而Windows的cmd命令查看ip地址是ipconfig.

  3. k8s获取apiversion下面的对应可用资源

    1- 获取api命令 [注:以下命令的url地址http://127.0.0.1/为k8s master的地址] kubectl api-versions 输出内容如下: apps/v1beta1 a ...

  4. overfitting &&underfitting

    1.过拟合 然能完美的拟合模型,但是拟合出来的模型会含有大量的参数,将会是一个含有大量参数的非常庞大的模型,因此不利于实现 1.1解决过拟合的方法 1.1.1 特征选择,通过选取特征变量来减少模型参数 ...

  5. MySQL的聚合函数

    MySQL的聚合函数 网站:https://www.runoob.com/mysql/mysql-functions.html 函数名 功能描述 count() 计数 sum() 求和 avg() 平 ...

  6. jarvis OJ部分writeup

    [XMAN]level 0 [XMAN]level 1 —— 简单shellcode利用 [XMAN]level 2 [XMAN]level 3 —— ret2libc尝试 [XMAN]level2& ...

  7. (四)tensorflow-基础(数据类型,张量操作,数学运算)

    摘要: 1.数据类型:标量.向量.矩阵.张量  :数值精度:变量(张量) 2.张量操作:索引.切片.维度操作 3.数学运算:加减乘除(整除和余除):乘方(平方.开方.指数):自然底对数(任意底对数需要 ...

  8. Selenium自动化发送163邮箱

    自动化发送163邮件 方法一: import time import datetime from selenium import webdriver from selenium.webdriver.s ...

  9. JS高级---沙箱

    沙箱 沙箱: 环境, 黑盒, 在一个虚拟的环境中模拟真实世界, 做实验, 实验结果和真实世界的结果是一样, 但是不会影响真实世界     全局变量 var num=10; console.log(nu ...

  10. date-fns时间库的基本使用

    在react中使用date-fns: import sub_days from 'date-fns/sub_days'; import start_of_week from 'date-fns/sta ...