102634: [AtCoder]ABC263 E - Sugoroku 3

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

There are $N$ squares called Square $1$ though Square $N$. You start on Square $1$.

Each of the squares from Square $1$ through Square $N-1$ has a die on it. The die on Square $i$ is labeled with the integers from $0$ through $A_i$, each occurring with equal probability. (Die rolls are independent of each other.)

Until you reach Square $N$, you will repeat rolling a die on the square you are on. Here, if the die on Square $x$ rolls the integer $y$, you go to Square $x+y$.

Find the expected value, modulo $998244353$, of the number of times you roll a die.

Notes

It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, there is a unique integer $R$ such that $R \times Q \equiv P\pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.

Constraints

  • $2 \le N \le 2 \times 10^5$
  • $1 \le A_i \le N-i(1 \le i \le N-1)$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\dots$ $A_{N-1}$

Output

Print the answer.


Sample Input 1

3
1 1

Sample Output 1

4

The sought expected value is $4$, so $4$ should be printed.

Here is one possible scenario until reaching Square $N$:

  • Roll $1$ on Square $1$, and go to Square $2$.
  • Roll $0$ on Square $2$, and stay there.
  • Roll $1$ on Square $2$, and go to Square $3$.

This scenario occurs with probability $\frac{1}{8}$.


Sample Input 2

5
3 1 2 1

Sample Output 2

332748122

Input

题意翻译

### 题目描述 一共有 $N$ 个格子编号 $1$ 到 $N$。有一个人站在 $1$ 号格子。 对于 $\forall i \in [1,N-1]$ 号格子有一个 $A_i + 1$ 面的骰子,写有 $0$ 到 $A_i$ 这些数。如果 ta 掷到了 $k$,他将往前走 $k$ 格,走到 $i+k$ 号方格。 求走到 $N$ 号方格的期望次数。对 $998244353$ 取模。 ### 输入格式 第一行一个正整数 $N$,第二行 $N-1$ 个正整数表示 $A_i$。 ### 输出格式 如果期望次数为 $\frac{P}{Q}$,输入最小非负整数 $R$ 使得 $R\times Q \equiv P\pmod {998244353}$。 ### 数据范围 $2\leq N\leq 2\times 10^5$ $\forall i \in [1,N-1],1\leq A_i\leq N-i$

Output

分数:500分

问题描述

有$N$个方块,分别称为方块1到方块$N$。你从方块1开始。

从方块1到方块$N-1$,每个方块上都有一个骰子。方块i上的骰子上标有从0到$A_i$的整数,每个出现的概率相等。(骰子掷出的结果是相互独立的。)

直到你到达方块$N$,你将重复在你所在方块上掷骰子。这里,如果方块$x$掷出的整数为$y$,你就去方块$x+y$。

求掷骰子次数的期望值,对998244353取模。

注意

可以证明所求期望值总是一个有理数。此外,如果该值用互素的整数$P$和$Q$表示为$\frac{P}{Q}$,则存在唯一的整数$R$,使得$R \times Q \equiv P\pmod{998244353}$且$0 \leq R \lt 998244353$。求这个$R$。

约束

  • $2 \le N \le 2 \times 10^5$
  • $1 \le A_i \le N-i(1 \le i \le N-1)$
  • 输入中的所有值都是整数。

输入

输入通过标准输入给出,如下所示:

$N$
$A_1$ $A_2$ $\dots$ $A_{N-1}$

输出

打印答案。


样例输入1

3
1 1

样例输出1

4

所求期望值为$4$,因此应打印$4$。

这是到达方块$N$的一种可能情况:

  • 在方块1上掷出$1$,然后去方块2。
  • 在方块2上掷出$0$,并留在那里。
  • 在方块2上掷出$1$,然后去方块3。

这种情况发生的概率为$\frac{1}{8}$。


样例输入2

5
3 1 2 1

样例输出2

332748122

加入题单

算法标签: