给明日的缎带AI (CI翻译)
Nephren has never been fond of long farewells. Before Chtholly leaves for her next mission, she says nothing and begins preparing a small ribbon for her instead.
Nephren 从来不喜欢漫长的道别。在 Chtholly 出发执行下一项任务之前,她什么也没有说,而是开始为她准备一条小缎带。AI (CI翻译)
She places $n$ glass beads in a row on the table before threading them onto the ribbon. Each bead is either white or black. A binary$^{\text{∗}}$ string $s$ represents their colors: the character $\mathtt{0}$ represents a white bead, and the character $\mathtt{1}$ represents a black bead.
在将玻璃珠穿到缎带上之前,Nephren 先把 $n$ 颗玻璃珠排成一行放在桌上。每颗珠子要么是白色,要么是黑色。二进制$^{\text{∗}}$字符串 $s$ 表示它们的颜色:字符 $\mathtt{0}$ 表示白色珠子,字符 $\mathtt{1}$ 表示黑色珠子。AI (CI翻译)
To make the arrangement less ordinary, Nephren turns it into a small game. She can perform the following operation any number of times (possibly zero):
为了让这个排列不那么普通,Nephren 把它变成了一个小游戏。她可以进行任意次(也可以是零次)以下操作:AI (CI翻译)
- Choose two indices
$l$and$r$($1 \le l \le r \le n$) such that$s_l=s_r$in the current string, and reverse$^{\text{†}}$the substring$s_l s_{l+1}\ldots s_r$.
- 选择两个下标
$l$和$r$($1 \le l \le r \le n$),使得当前字符串中$s_l=s_r$,然后将子串$s_l s_{l+1}\ldots s_r$反转$^{\text{†}}$。
For example, if $s=\mathtt{00110}$, Nephren may choose $l=1$ and $r=5$, since $s_1=s_5=\mathtt{0}$. After the operation, the string becomes $\mathtt{01100}$.
例如,当 $s=\mathtt{00110}$ 时,可以选择 $l=1$ 和 $r=5$,因为 $s_1=s_5=\mathtt{0}$。操作后,字符串变为 $\mathtt{01100}$。AI (CI翻译)
Determine the number of different binary strings that can be obtained from $s$. Since this number may be large, output it modulo $998\,244\,353$.
请确定从 $s$ 可以得到的不同二进制字符串的数量。由于答案可能很大,请将其对 $998\,244\,353$ 取模后输出。AI (CI翻译)
$^{\text{∗}}$A binary string is a string where each character is either $\mathtt 0$ or $\mathtt 1$.$^{\text{†}}$To reverse a substring $s_l s_{l+1}\ldots s_r$ means to replace it with $s_r s_{r-1}\ldots s_l$.
$^{\text{∗}}$二进制字符串是指其中每个字符都为 $\mathtt 0$ 或 $\mathtt 1$ 的字符串。$^{\text{†}}$将子串 $s_l s_{l+1}\ldots s_r$ 反转,意味着将其替换为 $s_r s_{r-1}\ldots s_l$。AI (CI翻译)
Input
输入
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains one integer $n$ ($1 \le n \le 10^6$) — the number of beads.
每个测试用例的第一行包含一个整数 $n$($1 \le n \le 10^6$),表示珠子的数量。AI (CI翻译)
The second line contains a binary string $s$ of length $n$, describing the colors of the beads.
第二行包含一个长度为 $n$ 的二进制字符串 $s$,表示珠子的颜色。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.
保证所有测试用例的 $n$ 之和不超过 $10^6$。AI (CI翻译)
Output
输出
AI (CI翻译)For each test case, output a single integer — the number of different binary strings that can be obtained from $s$, modulo $998\,244\,353$.
对于每个测试用例,输出一个整数,即从 $s$ 可以得到的不同字符串的数量,并将其对 $998\,244\,353$ 取模。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, exactly the following two strings can be obtained:
在第一个测试用例中,恰好可以得到以下两个字符串:AI (CI翻译)
$\mathtt{00110}$;$\mathtt{01100}$.
$\mathtt{00110}$;$\mathtt{01100}$。
For example, reversing the entire string $\mathtt{00110}$ produces $\mathtt{01100}$.
例如,将整个字符串 $\mathtt{00110}$ 反转后可以得到 $\mathtt{01100}$。AI (CI翻译)
In the second test case, exactly the following three strings can be obtained:
在第二个测试用例中,恰好可以得到以下三个字符串:AI (CI翻译)
$\mathtt{001010}$;$\mathtt{010010}$;$\mathtt{010100}$.
$\mathtt{001010}$;$\mathtt{010010}$;$\mathtt{010100}$。
For example, $\mathtt{010010}$ can be obtained by reversing the first four characters of $\mathtt{001010}$, and $\mathtt{010100}$ can be obtained by reversing the entire string $\mathtt{001010}$.
例如,将 $\mathtt{001010}$ 的前四个字符反转,可以得到 $\mathtt{010010}$;将整个字符串 $\mathtt{001010}$ 反转,可以得到 $\mathtt{010100}$。AI (CI翻译)
In the third test case, every substring whose endpoints contain the same character is a palindrome. Therefore, reversing any valid substring does not change the string, and only $\mathtt{01010}$ can be obtained.
在第三个测试用例中,所有端点包含相同字符的子串都是回文串。因此,反转任何合法的子串都不会改变字符串,最终只能得到 $\mathtt{01010}$。AI (CI翻译)
In the fourth test case, we can only get $\mathtt{111111}$.
在第四个测试用例中,我们只能得到 $\mathtt{111111}$。AI (CI翻译)
样例
4
5
00110
6
001010
5
01010
6
111111
2
3
1
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。