CF1762C.Binary Strings are Fun

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A binary string ^\dagger bb of odd length mm is good if bib_i is the median ^\ddagger of b[1,i]§b[1,i]^\S for all odd indices ii ( 1im1 \leq i \leq m ).

For a binary string aa of length kk , a binary string bb of length 2k12k-1 is an extension of aa if b2i1=aib_{2i-1}=a_i for all ii such that 1ik1 \leq i \leq k . For example, 1001011 and 1101001 are extensions of the string 1001. String x=x= 1011011 is not an extension of string y=y= 1001 because x3y2x_3 \neq y_2 . Note that there are 2k12^{k-1} different extensions of aa .

You are given a binary string ss of length nn . Find the sum of the number of good extensions over all prefixes of ss . In other words, find i=1nf(s[1,i])\sum_{i=1}^{n} f(s[1,i]) , where f(x)f(x) gives number of good extensions of string xx . Since the answer can be quite large, you only need to find it modulo 998244353998\,244\,353 .

^\dagger A binary string is a string whose elements are either 0\mathtt{0} or 1\mathtt{1} .

^\ddagger For a binary string aa of length 2m12m-1 , the median of aa is the (unique) element that occurs at least mm times in aa .

§^\S a[l,r]a[l,r] denotes the string of length rl+1r-l+1 which is formed by the concatenation of al,al+1,,ara_l,a_{l+1},\ldots,a_r in that order.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1041 \le t \le 10^4 ). The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ), where nn is the length of the binary string ss .

The second line of each test case contains the binary string ss of length nn .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print the answer modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    6
    1
    1
    1
    0
    2
    11
    3
    010
    9
    101101111
    37
    1011011111011010000011011111111011111

    输出#1

    1
    1
    3
    3
    21
    365

说明/提示

In the first and second test cases, f(s[1,1])=1f(s[1,1])=1 .

In the third test case, the answer is f(s[1,1])+f(s[1,2])=1+2=3f(s[1,1])+f(s[1,2])=1+2=3 .

In the fourth test case, the answer is f(s[1,1])+f(s[1,2])+f(s[1,3])=1+1+1=3f(s[1,1])+f(s[1,2])+f(s[1,3])=1+1+1=3 .

f(11)=2f(\mathtt{11})=2 because two good extensions are possible: 101 and 111.

f(01)=1f(\mathtt{01})=1 because only one good extension is possible: 011.

首页