CF2201E.ABBA Counting

省选/NOI-

通过率:0%

时间限制:3.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string TT of length nn (nn is even), which consists of 'a', 'b', and '?'.

Please count the strings SS which satisfy the following conditions:

  • ∣S∣=n|S|=n;
  • SiS_i is either 'a' or 'b' for all 1≤i≤n1 \le i \le n;
  • Si=TiS_i=T_i for all 1≤i≤n1 \le i \le n such that TiT_i is not '?';
  • There exist two (possibly empty) strings AA and BB such that S=A+B+B+AS=A+B+B+A. Here, ++ denotes string concatenation.

As the answer may be inexplicably huge, you are only asked to compute it modulo 998 244 353998\,244\,353.

给你一个长度为 nn(nn 为偶数)的字符串 TT,它仅由字符 'a'、'b' 和 '?' 组成。

请计算满足以下条件的字符串 SS 的个数:

  • ∣S∣=n|S|=n;
  • 对所有 1≤i≤n1 \le i \le n,SiS_i 为 'a' 或 'b';
  • 对所有满足 Ti≠ ’?’T_i \neq\, \text{'?'} 的下标 ii(1≤i≤n1 \le i \le n),有 Si=TiS_i=T_i;
  • 存在两个(可能为空)字符串 AA 和 BB,使得 S=A+B+B+AS=A+B+B+A。此处 ++ 表示字符串连接。

由于答案可能极其巨大,你只需输出其对 998 244 353998\,244\,353 取模的结果。

输入格式

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

The first line of each test case contains a single integer nn (2≤n≤400 0002 \le n \le 400\,000, nn is even).

The second line of each test case contains a string TT of length nn, consisting of 'a', 'b', and '?'.

It is guaranteed that the sum of nn over all test cases does not exceed 400 000400\,000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤400 0002 \le n \le 400\,000,且 nn 为偶数)。

每个测试用例的第二行包含一个长度为 nn 的字符串 TT,由字符 'a'、'b' 和 '?' 组成。

保证所有测试用例的 nn 之和不超过 400 000400\,000。

输出格式

For each test case, output the answer modulo 998 244 353998\,244\,353 on a separate line.

对于每个测试用例,在单独一行中输出答案对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#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 1010 corresponding strings which are as follows:

  1. "aaaabaaaaaba"
  2. "aaaabbaaabba"
  3. "aaabbaaaabba"
  4. "aaabbbaabbba"
  5. "abaabbbaabba"
  6. "ababbbbabbba"
  7. "baaabaaababa"
  8. "baaababaaaba"
  9. "baaabbaabbba"
  10. "baabbabaabba"

对于第五个测试用例,共有 1010 个对应的字符串,如下所示:

  1. "aaaabaaaaaba"
  2. "aaaabbaaabba"
  3. "aaabbaaaabba"
  4. "aaabbbaabbba"
  5. "abaabbbaabba"
  6. "ababbbbabbba"
  7. "baaabaaababa"
  8. "baaababaaaba"
  9. "baaabbaabbba"
  10. "baabbabaabba"

输入解题思路,AI测评打分。不知道怎么写?

首页