CF2201E.ABBA Counting
省选/NOI-
通过率:0%
时间限制:3.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string T of length n (n is even), which consists of 'a', 'b', and '?'.
Please count the strings S which satisfy the following conditions:
- ∣S∣=n;
- Si is either 'a' or 'b' for all 1≤i≤n;
- Si=Ti for all 1≤i≤n such that Ti is not '?';
- There exist two (possibly empty) strings A and B such that S=A+B+B+A. Here, + denotes string concatenation.
As the answer may be inexplicably huge, you are only asked to compute it modulo 998244353.
给你一个长度为 n(n 为偶数)的字符串 T,它仅由字符 'a'、'b' 和 '?' 组成。
请计算满足以下条件的字符串 S 的个数:
- ∣S∣=n;
- 对所有 1≤i≤n,Si 为 'a' 或 'b';
- 对所有满足 Ti=’?’ 的下标 i(1≤i≤n),有 Si=Ti;
- 存在两个(可能为空)字符串 A 和 B,使得 S=A+B+B+A。此处 + 表示字符串连接。
由于答案可能极其巨大,你只需输出其对 998244353 取模的结果。
输入格式
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 (2≤n≤400000, n is even).
The second line of each test case contains a string T of length n, consisting of 'a', 'b', and '?'.
It is guaranteed that the sum of n over all test cases does not exceed 400000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤400000,且 n 为偶数)。
每个测试用例的第二行包含一个长度为 n 的字符串 T,由字符 'a'、'b' 和 '?' 组成。
保证所有测试用例的 n 之和不超过 400000。
输出格式
For each test case, output the answer modulo 998244353 on a separate line.
对于每个测试用例,在单独一行中输出答案对 998244353 取模的结果。
输入输出样例
输入#1
6 2 a? 2 ?? 4 a??a 4 ab?? 12 ??a?b??a??ba 12 ?ab???b??a??
输出#1
1 2 2 2 10 22
说明/提示
For the fifth test case, there are 10 corresponding strings which are as follows:
- "aaaabaaaaaba"
- "aaaabbaaabba"
- "aaabbaaaabba"
- "aaabbbaabbba"
- "abaabbbaabba"
- "ababbbbabbba"
- "baaabaaababa"
- "baaababaaaba"
- "baaabbaabbba"
- "baabbabaabba"
对于第五个测试用例,共有 10 个对应的字符串,如下所示:
- "aaaabaaaaaba"
- "aaaabbaaabba"
- "aaabbaaaabba"
- "aaabbbaabbba"
- "abaabbbaabba"
- "ababbbbabbba"
- "baaabaaababa"
- "baaababaaaba"
- "baaabbaabbba"
- "baabbabaabba"
输入解题思路,AI测评打分。不知道怎么写?