出错的或电路
标题:出错的或电路 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
某生产门电路的厂商发现某一批次的或门电路不稳定,具体现象为计算两个二进制数的或操作时,第一个二进制数中某两个比特位会出现交换,交换的比特位置是随机的,但只交换这两个位,其他位不变。很明显,这个交换可能会影响最终的或结果,也可能不会有影响。为了评估影响和定位出错的根因,工程师需要研究在各种交换的可能下,最终的或结果发生改变的情况有多少种。
n = int(input()) a = input() b = input() c = [] cnt = [0] * 2 for i in range(n): if b[i] == '0': c.append(int(a[i])) if a[i] == '0': cnt[0] += 1 else: cnt[1] += 1 total = 0 for i in range(len(c)): total += cnt[c[i] ^ 1] cnt[c[i]] -= 1 print(total)