#P9151. 计数题

    ID: 9972 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP数学洛谷原创O2优化组合数学洛谷月赛

计数题

Background

Easy Counting Problem

身のうさを思ひしらでややみなまし そむくならひのなき世なりせば

Problem Description

Given a binary string SS of length NN, you can perform some operations. In each operation, choose a substring of length 33 and replace it with its median (note that it becomes a single digit). Ask how many different strings can be obtained.

Output the answer modulo 998244353998244353.

Input Format

This problem has multiple test cases. The first line contains the number of test cases TT.

For each test case, input only one string SS, representing the given binary string.

Output Format

For each test case, output one integer per line, which is the answer modulo 998244353998244353.

4
1001
111000
101010
111000101010

3
7
3
25

Hint

Sample Explanation

It can be proven that 10011001 can only obtain the strings 1010, 0101, and 10011001 through the operations, so the answer for the first test case in the sample is 33.


Constraints

For 100%100\% of the testdata, 1N5×1061 \le N \le 5\times {10}^6, Si{0,1}S_i \in \{0,1\}, and 1T51 \le T \le 5.

Subtask NN \le Special Property Score
1 1010 55
2 5050 1010
3 300300
4 20002000 1515
5 A 55
6 B
7 105{10}^5 2020
8 3030

Special Property A: It is guaranteed that Si=0S_i = 0.

Special Property B: It is guaranteed that S2k=0S_{2k} = 0 and S2k+1=1S_{2k+1} = 1.

String indices start from 11.

Translated by ChatGPT 5