CF1778D.Flexible String Revisit
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
给你两个长度为 n 的二进制字符串 a 和 b。在每一步操作中,字符串 a 按如下方式被修改:
- 均匀随机地选择一个下标 i(1≤i≤n),并将字符 ai 翻转:即若 ai 为 0,则变为 1;若 ai 为 1,则变为 0。
问:使两个字符串首次相等所需的期望操作次数是多少?
二进制字符串是指仅由字符 0 或 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.
第一行包含一个整数 t(1≤t≤105)—— 表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤106)—— 表示字符串的长度。
每个测试用例的第二行包含一个长度为 n 的二进制字符串 a。
每个测试用例的第三行包含一个长度为 n 的二进制字符串 b。
保证所有测试用例的 n 之和不超过 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).
对于每个测试用例,输出一行,包含期望移动次数对 998244353 取模的结果。
形式化地,令 M=998244353。可以证明答案可表示为既约分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出整数 p⋅q−1modM。换言之,请输出满足 0≤x<M 且 x⋅q≡p(modM) 的整数 x。
输入输出样例
输入#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.
在第一个测试用例中,随机选择索引 1 并翻转 a1。操作后,字符串 a 和 b 相等。期望操作次数为 1。
在第二个测试用例中,字符串 a 和 b 已经相等,因此期望操作次数为 0。
第三个和第四个测试用例的期望操作次数分别为 356 和 3125。
输入解题思路,AI测评打分。不知道怎么写?