CF1017B.The Bits

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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, 01010201010_2 OR 10011210011_2 = 11011211011_2.

Well, to your surprise, you are not Rudolf, and you don't need to help him…\ldots You are the security staff! Please find the number of ways of swapping two bits in aa so that bitwise OR will be changed.

鲁道夫正在前往城堡的路上。在进入城堡之前,安保人员向他提出了一个问题:

给定两个长度为 nn 的二进制数 aa 和 bb。有多少种不同的方式,仅在 aa 中交换两个数字(不能动 bb),使得这两个数的按位或(bitwise OR)结果发生改变?换言之,设 cc 为 aa 与 bb 的按位或结果,你需要计算在 aa 中交换两个比特位的方式总数,使得交换后新的按位或结果不等于 cc。

注意:二进制数可以包含前导零,因此每个数的长度恰好为 nn。

按位或 是一种二元运算。其结果是一个二进制数,当且仅当两个操作数中至少有一个在某一位上为 1 时,结果在该位上为 1。例如,01010201010_2 OR 10011210011_2 = 11011211011_2。

好吧,令你惊讶的是,你并不是鲁道夫,也无需帮助他…… 你是安保人员!请计算在 aa 中交换两个比特位的方式总数,使得按位或结果发生改变。

输入格式

The first line contains one integer nn (2≤n≤1052\leq n\leq 10^5) — 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.

第一行包含一个整数 nn(2≤n≤1052\leq n\leq 10^5)—— 表示每个数字的二进制位数。

第二行包含一个长度为 nn 的二进制数 aa。

第三行包含一个长度为 nn 的二进制数 bb。

输出格式

Print the number of ways to swap two bits in aa so that bitwise OR will be changed.

打印交换 aa 中两个比特位使得按位或(bitwise OR)结果发生变化的方法数。

输入输出样例

  • 输入#1

    5
    01011
    11001

    输出#1

    4
  • 输入#2

    6
    011000
    010011

    输出#2

    6

说明/提示

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

在第一个样例中,你可以交换索引为 (1,4)(1, 4)、(2,3)(2, 3)、(3,4)(3, 4) 和 (3,5)(3, 5) 的比特位。

在第二个样例中,你可以交换索引为 (1,2)(1, 2)、(1,3)(1, 3)、(2,4)(2, 4)、(3,4)(3, 4)、(3,5)(3, 5) 和 (3,6)(3, 6) 的比特位。

输入解题思路,AI测评打分。不知道怎么写?

首页