CF2061C.Kevin and Puzzle

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kevin enjoys logic puzzles.

He played a game with nn classmates who stand in a line. The ii-th person from the left says that there are aia_i liars to their left (not including themselves).

Each classmate is either honest or a liar, with the restriction that no two liars can stand next to each other. Honest classmates always say the truth. Liars can say either the truth or lies, meaning their statements are considered unreliable.

Kevin wants to determine the number of distinct possible game configurations modulo 998 244 353998\,244\,353. Two configurations are considered different if at least one classmate is honest in one configuration and a liar in the other.

凯文喜欢逻辑谜题。

他和 nn 位同学玩了一个游戏,这些同学排成一列。从左往右数第 ii 位同学声称:在其左侧(不包括自己)有 aia_i 个说谎者。

每位同学要么是诚实者,要么是说谎者,且有一个限制条件:任意两个说谎者不能相邻。诚实者总是说真话;而说谎者则可能说真话也可能说假话,即他们的陈述不可靠。

凯文希望计算出满足条件的不同游戏配置总数,并对 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 an integer nn (1≤n≤2⋅1051\leq n \leq 2 \cdot 10^5) — the number of classmates.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤n0\leq a_i \leq n) — the number of liars to the left of the ii-th person they claimed.

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(1≤n≤2⋅1051\leq n \leq 2 \cdot 10^5)—— 同学的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤n0\leq a_i \leq n)—— 第 ii 个人所声称的其左侧说谎者的人数。

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

输出格式

For each test case, output one integer — the number of distinct game configurations modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——不同的游戏配置数目对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    8
    3
    0 1 2
    5
    0 0 0 0 0
    5
    0 0 1 1 2
    5
    0 1 2 3 4
    5
    0 0 1 1 1
    5
    5 1 5 2 5
    1
    0
    4
    2 3 1 1

    输出#1

    1
    2
    3
    0
    4
    1
    2
    0

说明/提示

We will use red\color{red}{\text{red}} to mark liars and blue\color{blue}{\text{blue}} to mark honest people.

In the first test case, the only possible way is (0,1,2)(\color{red}{0},\color{blue}{1},\color{red}{2}).

In the second test case, two possible ways are (0,0,0,0,0)(\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0}) and (0,0,0,0,0)(\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{red}{0}).

In the third test case, three possible ways are (0,0,1,1,2)(\color{blue}{0},\color{blue}{0},\color{red}{1},\color{blue}{1},\color{red}{2}), (0,0,1,1,2)(\color{blue}{0},\color{red}{0},\color{blue}{1},\color{red}{1},\color{blue}{2}), (0,0,1,1,2)(\color{blue}{0},\color{red}{0},\color{blue}{1},\color{blue}{1},\color{red}{2}).

我们将用 红色\color{red}{\text{红色}} 标记说谎者,用 蓝色\color{blue}{\text{蓝色}} 标记诚实者。

在第一个测试用例中,唯一可能的情况是 (0,1,2)(\color{red}{0},\color{blue}{1},\color{red}{2})。

在第二个测试用例中,两种可能的情况是 (0,0,0,0,0)(\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0}) 和 (0,0,0,0,0)(\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{blue}{0},\color{red}{0})。

在第三个测试用例中,三种可能的情况是 (0,0,1,1,2)(\color{blue}{0},\color{blue}{0},\color{red}{1},\color{blue}{1},\color{red}{2})、(0,0,1,1,2)(\color{blue}{0},\color{red}{0},\color{blue}{1},\color{red}{1},\color{blue}{2})、(0,0,1,1,2)(\color{blue}{0},\color{red}{0},\color{blue}{1},\color{blue}{1},\color{red}{2})。

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

首页