CF1762C.Binary Strings are Fun
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A binary string † b of odd length m is good if bi is the median ‡ of b[1,i]§ for all odd indices i ( 1≤i≤m ).
For a binary string a of length k , a binary string b of length 2k−1 is an extension of a if b2i−1=ai for all i such that 1≤i≤k . For example, 1001011 and 1101001 are extensions of the string 1001. String x= 1011011 is not an extension of string y= 1001 because x3=y2 . Note that there are 2k−1 different extensions of a .
You are given a binary string s of length n . Find the sum of the number of good extensions over all prefixes of s . In other words, find ∑i=1nf(s[1,i]) , where f(x) gives number of good extensions of string x . Since the answer can be quite large, you only need to find it modulo 998244353 .
† A binary string is a string whose elements are either 0 or 1 .
‡ For a binary string a of length 2m−1 , the median of a is the (unique) element that occurs at least m times in a .
§ a[l,r] denotes the string of length r−l+1 which is formed by the concatenation of al,al+1,…,ar in that order.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤2⋅105 ), where n is the length of the binary string s .
The second line of each test case contains the binary string s of length n .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, print the answer modulo 998244353 .
输入输出样例
输入#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])=1 .
In the third test case, the answer is f(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=3 .
f(11)=2 because two good extensions are possible: 101 and 111.
f(01)=1 because only one good extension is possible: 011.