atcoder#ABC200F. [ABC200F] Minflip Summation
[ABC200F] Minflip Summation
Score : points
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.
101
2
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.
?0?
1
3
We have four candidates for : 000
, 001
, 100
, and 101
.
10111?10??1101??1?00?1?01??00010?0?1??
998244353
235562598
Since the answer can be enormous, find it modulo .