No.2275 →↑↓
Problem Statement
There is an infinitely large $2$-dimensional grid. Each cell is painted white or black. Specifically, for each $i = 1, 2, \ldots, N$, cells $(i, 1), (i, 2), \ldots, (i, A_i)$ are painted white, and all other cells are painted black.
Initially, Magusuta is at cell $(1, 1)$. He is trying to reach cell $(N, 1)$ by repeating the following action.
- Let $(i, j)$ be the cell he is currently on. Paint cell $(i, j)$ black. Then, choose $1$ white cell among cells $(i + 1, j), (i, j + 1), (i, j - 1)$ and move to that cell.
Find the number of ways to reach cell $(N, 1)$, modulo $998244353$.
Input
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
- All input values are integers.
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq A_i \leq 10^9$
Output
Print the number of ways to reach cell $(N, 1)$, modulo $998244353$. Print a newline at the end.
Sample
Sample 1
Input
3 1 3 2
Output
2
The cells painted white are $(1, 1), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2)$. There are the following $2$ ways to move.
- $(1, 1) \to (2, 1) \to (3, 1)$
- $(1, 1) \to (2, 1) \to (2, 2) \to (3, 2) \to (3, 1)$
Sample 2
Input
5 427547210 327546386 963298277 230265126 293165710
Output
538454432
Print the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
miscalc
magsta