Domino TilesAI (CI翻译)
Nygglatho returns from the market with an old box of tiles whose painted marks have begun to fade. Before she can put it away, Chtholly and the young fairies have already spread the tiles across the dining table and turned them into a puzzle.
There is a row of $n$ tiles. Each tile should be marked with either $\mathtt 0$ or $\mathtt 1$. However, some of the marks have faded away.
The current row is represented by a string $s$ of length $n$. Each character of $s$ is $\mathtt{0}$, $\mathtt{1}$, or $\mathtt{?}$. Chtholly must replace every $\mathtt{?}$ with either $\mathtt{0}$ or $\mathtt{1}$.
After replacement, for every $1 \le i \lt n$, the two neighboring tiles $s_i$ and $s_{i+1}$ form a domino of weight $(s_i + s_{i+1})$. Note that two consecutive dominoes share exactly one tile. The completed row is valid if every two consecutive dominoes have different weights.
Determine the number of different$^{\text{∗}}$ ways to replace all $\mathtt{?}$ characters so that the completed row is valid. Output the answer modulo $998\,244\,353$.
$^{\text{∗}}$Two ways of replacement are considered different if the resulting strings are different.
Input
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.
The first line of each test case contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of tiles.
The second line contains the string $s$ of length $n$, where $s_i= \mathtt{0}$, $\mathtt{1}$, or $\mathtt{?}$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
Output
For each test case, output one integer — the number of valid ways to replace all $\mathtt{?}$ characters, modulo $998\,244\,353$.
Note
In the first test case, there is only one domino, so every completion is valid. The valid completed strings are $\mathtt{00}$, $\mathtt{01}$, $\mathtt{10}$, and $\mathtt{11}$.
In the second test case, the valid completed strings are $\mathtt{00110}$ and $\mathtt{01100}$.
In the third test case, there are no valid completed strings.
In the fourth test case, the only valid completed string is $\mathtt{00110011}$.
{"titleZh":"多米诺骨牌","bodyZh":"Nygglatho 从集市带回了一盒旧骨牌,上面的图案已经开始褪色。她还没来得及收好,Chtholly 和年轻的妖精们就已经把骨牌铺满了餐桌,将它们变成了一道谜题。\n\n有一排 $n$ 块骨牌。每块骨牌都应标记为 $\mathtt 0$ 或 $\mathtt 1$,但其中一些标记已经褪去了。\n\n当前这一排骨牌用一个长度为 $n$ 的字符串 $s$ 表示。$s$ 中的每个字符都是 $\mathtt{0}$、$\mathtt{1}$ 或 $\mathtt{?}$。Chtholly 必须将每个 $\mathtt{?}$ 替换为 $\mathtt{0}$ 或 $\mathtt{1}$。\n\n替换完成后,对于每个 $1 \\le i \\lt n$,相邻两块骨牌 $s_i$ 和 $s_{i+1}$ 构成一块重量为 $(s_i + s_{i+1})$ 的多米诺骨牌。注意,相邻的两块多米诺骨牌恰好共用一块骨牌。若每两块相邻多米诺骨牌的重量都不同,则完成后的这一排骨牌是有效的。\n\n请计算将所有 $\mathtt{?}$ 替换为 $\mathtt{0}$ 或 $\mathtt{1}$,使完成后的这一排骨牌有效的不同$^{\\text{∗}}$替换方案数。答案对 $998\\,244\\,353$ 取模。\n\n$^{\\text{∗}}$如果两种替换得到的字符串不同,则认为它们是不同的方案。\n\n## 输入格式\n\n每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \\le t \\le 10^4$)。接下来是各测试用例的描述。\n\n每个测试用例的第一行包含一个整数 $n$($2 \\le n \\le 2 \\cdot 10^5$),表示骨牌的数量。\n\n第二行包含一个长度为 $n$ 的字符串 $s$,其中 $s_i= \\mathtt{0}$、$\\mathtt{1}$ 或 $\u005cmathtt{?}$。\n\n保证所有测试用例的 $n$ 之和不超过 $2 \\cdot 10^5$。\n\n## 输出格式\n\n对于每个测试用例,输出一个整数,表示将所有 $\u005cmathtt{?}$ 替换后使这一排骨牌有效的方案数,结果对 $998\\,244\\,353$ 取模。\n\n## 说明\n\n在第一个测试用例中,只有一块多米诺骨牌,因此所有补全方式都有效。有效的完成字符串为 $\u005cmathtt{00}$、$\u005cmathtt{01}$、$\u005cmathtt{10}$ 和 $\u005cmathtt{11}$。\n\n在第二个测试用例中,有效的完成字符串为 $\u005cmathtt{00110}$ 和 $\u005cmathtt{01100}$。\n\n在第三个测试用例中,不存在有效的完成字符串。\n\n在第四个测试用例中,唯一有效的完成字符串是 $\u005cmathtt{00110011}$."}AI (CI翻译)
样例
4
2
??
5
0?1??
5
0?0??
8
00110011
4
2
0
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。