#P15771. [JAG 2025 Summer Camp #2] 00 → 1
[JAG 2025 Summer Camp #2] 00 → 1
Description
For any binary string , define as follows.
You may apply the following three operations on any number of times (possibly zero), in any order:
- Operation 1: Swap two adjacent characters.
- Operation 2: Choose a contiguous substring "00" and replace it with "1".
- Operation 3: Choose a contiguous substring "11" and replace it with "0".
Let be the minimum number of operations required to make the string equal to either "0", "1", or "01". If it is impossible to transform into any of these strings, we define .
You are given a binary string .
Compute $\left( \sum \limits_{1 \leq l \leq r \leq N} f(S_l S_{l+1} \ldots S_r) \right) \bmod 998244353$.
Input Format
The input consists of a single test case of the following format.
$$\begin{aligned} & N \\ & S_1 S_2 \ldots S_N \end{aligned}$$The first line contains an integer (), the length of the string. The second line contains a binary string . Each character () is either '0' or '1'.
Output Format
Print the answer.
4
0100
10
10
1110001100
152
京公网安备 11011102002149号