CF1778D.Flexible String Revisit

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given two binary strings aa and bb of length nn . In each move, the string aa is modified in the following way.

  • An index ii ( 1in1 \leq i \leq n ) is chosen uniformly at random. The character aia_i will be flipped. That is, if aia_i is 00 , it becomes 11 , and if aia_i is 11 , it becomes 00 .

What is the expected number of moves required to make both strings equal for the first time?

A binary string is a string, in which the character is either 0\tt{0} or 1\tt{1} .

输入格式

The first line contains a single integer tt ( 1t1051 \leq t \leq 10^5 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n1061 \leq n \leq 10^6 ) — the length of the strings.

The second line of each test case contains the binary string aa of length nn .

The third line of each test case contains the binary string bb of length nn .

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 .

输出格式

For each test case, output a single line containing the expected number of moves modulo 998244353998\,244\,353 .

Formally, let M=998244353M = 998\,244\,353 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output such an integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入输出样例

  • 输入#1

    4
    1
    0
    1
    2
    00
    00
    4
    1000
    1110
    5
    01001
    10111

    输出#1

    1
    0
    665496254
    665496277

说明/提示

In the first test case, index 11 is chosen randomly and a1a_1 is flipped. After the move, the strings aa and bb are equal. The expected number of moves is 11 .

The strings aa and bb are already equal in the second test case. So, the expected number of moves is 00 .

The expected number of moves for the third and fourth test cases are 563\frac{56}{3} and 1253\frac{125}{3} respectively.

首页