#abc200f. F - Minflip Summation
F - Minflip Summation
Score : points
问题描述
我们有一个由 0
、1
和 ?
组成的字符串 。令 为将 连接 次得到的字符串。
通过将 中的每个 ?
替换为 0
或 1
,我们可以得到 个不同的字符串,其中 是 中 ?
的数量。针对这些字符串中的每一个解决以下问题,并求出所有答案之和,结果对 取模。
让 表示通过替换 中的
?
得到的字符串。我们将重复执行以下操作以使 中的所有字符变得相同。至少需要多少次操作才能实现这一点?
- 选择整数 和 ,满足 ,然后反转 中第 到第 个字符:即将
0
和1
互换。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a string consisting of 0
, 1
, and ?
. Let be the concatenation of copies of .
By replacing each ?
in with 0
or 1
, we can obtain strings, where is the number of ?
s in . Solve the problem below for each of these strings and find the sum of all the answers, modulo .
Let be the string obtained by replacing
?
in . We will repeatedly do the operation below to make all the characters in the same. At least how many operations are needed for this?
- Choose integers and such that , and invert the -th through -th characters of : from
0
and1
and vice versa.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
101
2
Sample Output 1
2
We have 101101
, which does not contain ?
, so we just need to solve the problem for the only 101101
.
We can make all the characters the same in two operations as, for example, 101101
110011
111111
.
We cannot make all the characters the same in one or fewer operations.
Sample Input 2
?0?
1
Sample Output 2
3
We have four candidates for : 000
, 001
, 100
, and 101
.
Sample Input 3
10111?10??1101??1?00?1?01??00010?0?1??
998244353
Sample Output 3
235562598
Since the answer can be enormous, find it modulo .
update @ 2024/3/10 09:12:29