QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 256 MB Puntuación total: 100

#11618. 旅程

Estadísticas

在一条直线上有 $n$ 个格子,编号从 $1$ 到 $n$。每个格子 $i$ 中包含一个数字 $a_i$。初始时,玩家位于 $1$ 号格子,手中持有的数字为 $h_0$。

如果玩家当前位于编号为 $p$ ($1 \le p \le n$) 的格子,且手中持有的数字为 $h$,则他可以跳到编号为 $p + a_p$ 的格子,或者跳到编号为 $p + h$ 的格子。禁止跳出直线范围。跳跃后,玩家手中持有的新数字等于上一次跳跃的距离。

你需要计算从 $1$ 号格子到 $n$ 号格子的路径数量。如果两条路径经过的格子集合不同,则认为它们是不同的。请输出答案对 $998\,244\,353$ 取模的结果。

输入格式

第一行包含两个整数 $n$ 和 $h_0$:直线上格子的数量以及路径开始前玩家手中持有的数字 ($2 \le n \le 100\,000$; $1 \le h_0 \le n - 1$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$。其中 $a_i$ 是第 $i$ 个格子中的数字 ($1 \le a_i \le n - 1$)。

输出格式

输出一个整数:不同路径的数量对 $998\,244\,353$ 取模的结果。

样例

样例输入 1

5 1
2 3 2 4 3

样例输出 1

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.