CF2256B.Domino Tiles

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 nn tiles. Each tile should be marked with either 0\mathtt 0 or 1\mathtt 1. However, some of the marks have faded away.

The current row is represented by a string ss of length nn. Each character of ss is 0\mathtt{0}, 1\mathtt{1}, or ?\mathtt{?}. Chtholly must replace every ?\mathtt{?} with either 0\mathtt{0} or 1\mathtt{1}.

After replacement, for every 1≤i<n1 \le i \lt n, the two neighboring tiles sis_i and si+1s_{i+1} form a domino of weight (si+si+1)(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 353998\,244\,353.

∗^{\text{∗}}Two ways of replacement are considered different if the resulting strings are different.

尼格拉索从市场归来,带回了一个装有旧瓷砖的盒子,瓷砖上的彩绘标记已经开始褪色。她还没来得及把盒子收好,楚托莉和一群小精灵就已经把瓷砖铺满了餐桌,并将其变成了一道谜题。

有一排 nn 块瓷砖。每块瓷砖上应标有 0\mathtt{0} 或 1\mathtt{1}。然而,其中一些标记已经褪色。

当前这一排用一个长度为 nn 的字符串 ss 表示。ss 的每个字符为 0\mathtt{0}、1\mathtt{1} 或 ?\mathtt{?}。楚托莉必须将每个 ?\mathtt{?} 替换为 0\mathtt{0} 或 1\mathtt{1}。

替换完成后,对每个 1≤i<n1 \le i \lt n,相邻的两块瓷砖 sis_i 与 si+1s_{i+1} 构成一个权值为 (si+si+1)(s_i + s_{i+1}) 的多米诺骨牌。注意:两个连续的多米诺骨牌恰好共享一块瓷砖。若完成后的整排中,任意两个连续的多米诺骨牌权值均不相同,则称该排是有效的。

求出将所有 ?\mathtt{?} 替换为 0\mathtt{0} 或 1\mathtt{1} 后,使得整排有效的不同方式数目(模 998 244 353998\,244\,353)。

∗^{\text{∗}} 若两种替换方式所得字符串不同,则认为它们是不同的方式。

输入格式

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 one integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of tiles.

The second line contains the string ss of length nn, where si=0s_i= \mathtt{0}, 1\mathtt{1}, or ?\mathtt{?}.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 表示瓷砖的数量。

第二行包含一个长度为 nn 的字符串 ss,其中每个字符 sis_i 为 0\mathtt{0}、1\mathtt{1} 或 ?\mathtt{?}。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output one integer — the number of valid ways to replace all ?\mathtt{?} characters, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——将所有 ?\mathtt{?} 字符替换为有效字符的方案数,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    4
    2
    ??
    5
    0?1??
    5
    0?0??
    8
    00110011

    输出#1

    4
    2
    0
    1

说明/提示

In the first test case, there is only one domino, so every completion is valid. The valid completed strings are 00\mathtt{00}, 01\mathtt{01}, 10\mathtt{10}, and 11\mathtt{11}.

In the second test case, the valid completed strings are 00110\mathtt{00110} and 01100\mathtt{01100}.

In the third test case, there are no valid completed strings.

In the fourth test case, the only valid completed string is 00110011\mathtt{00110011}.

在第一个测试用例中,只有一个多米诺骨牌,因此所有补全方案均有效。有效的补全字符串为 00\mathtt{00}、01\mathtt{01}、10\mathtt{10} 和 11\mathtt{11}。

在第二个测试用例中,有效的补全字符串为 00110\mathtt{00110} 和 01100\mathtt{01100}。

在第三个测试用例中,不存在有效的补全字符串。

在第四个测试用例中,唯一有效的补全字符串为 00110011\mathtt{00110011}。

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

首页