B. The Bits
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:
Given two binary numbers aa and bb of length nn . How many different ways of swapping two digits in aa (only in aa , not bb ) so that bitwise OR of these two numbers will be changed? In other words, let cc be the bitwise OR of aa and bb , you need to find the number of ways of swapping two bits in aa so that bitwise OR will not be equal to cc .
Note that binary numbers can contain leading zeros so that length of each number is exactly nn .
Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 010102010102 OR 100112100112 = 110112110112 .
Well, to your surprise, you are not Rudolf, and you don't need to help him…… You are the security staff! Please find the number of ways of swapping two bits in aa so that bitwise OR will be changed.
Input
The first line contains one integer nn (2≤n≤1052≤n≤105 ) — the number of bits in each number.
The second line contains a binary number aa of length nn .
The third line contains a binary number bb of length nn .
Output
Print the number of ways to swap two bits in aa so that bitwise OR will be changed.
Examples
Input
Copy
5 01011 11001
Output
Copy
4
Input
Copy
6 011000 010011
Output
Copy
6
Note
In the first sample, you can swap bits that have indexes (1,4)(1,4) , (2,3)(2,3) , (3,4)(3,4) , and (3,5)(3,5) .
In the second example, you can swap bits that have indexes (1,2)(1,2) , (1,3)(1,3) , (2,4)(2,4) , (3,4)(3,4) , (3,5)(3,5) , and (3,6)(3,6) .
#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<queue>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll unsigned long long
#define MAX 1000000000
#define ms memset
#define maxn 200005
using namespace std;
char a[maxn],b[maxn];
/*
题目大意:给定两个二进制数,
变动a中的两个数,使得其或值产生影响。
问有多少种方法
可枚举所有产生变动的情况,
然后组合计数即可。
总共有四种配对情况,
(0,0),(0,1),
(1,0),(1,1)。
可知00与10,11互换会产生影响,
01与10互换会产生影响,
这样,遍历扫一遍计数然后相乘即可
*/
int main()
{
int n;cin>>n;
cin>>a+1;
cin>>b+1;
ll cnt00=0,cnt01=0,cnt10=0,cnt11=0;
for(int i=1;i<=n;i++)
{
if(a[i]==b[i])
{
if(a[i]=='0') cnt00++;
else cnt11++;
}
else
{
if(a[i]=='0') cnt01++;
else cnt10++;
}
}
cout<<cnt00*cnt11+cnt01*cnt10+cnt00*cnt10<<endl;
return 0;
}