CF1778D.Flexible String Revisit
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two binary strings a and b of length n . In each move, the string a is modified in the following way.
- An index i ( 1≤i≤n ) is chosen uniformly at random. The character ai will be flipped. That is, if ai is 0 , it becomes 1 , and if ai is 1 , it becomes 0 .
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 or 1 .
输入格式
The first line contains a single integer t ( 1≤t≤105 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤106 ) — the length of the strings.
The second line of each test case contains the binary string a of length n .
The third line of each test case contains the binary string b of length n .
It is guaranteed that the sum of n over all test cases does not exceed 106 .
输出格式
For each test case, output a single line containing the expected number of moves modulo 998244353 .
Formally, let M=998244353 . It can be shown that the answer can be expressed as an irreducible fraction qp , where p and q are integers and q≡0(modM) . Output the integer equal to p⋅q−1modM . In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM) .
输入输出样例
输入#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 1 is chosen randomly and a1 is flipped. After the move, the strings a and b are equal. The expected number of moves is 1 .
The strings a and b are already equal in the second test case. So, the expected number of moves is 0 .
The expected number of moves for the third and fourth test cases are 356 and 3125 respectively.