estie プログラミングコンテスト2023 (AtCoder Regular Contest 169)
翻译中…
Problem Statement
翻译中…
You are given an integer $N$. An integer sequence $x=(x_1,x_2,\cdots,x_N)$ of length $N$ is called a good sequence if and only if the following conditions are satisfied:
翻译中…
- Each element of
$x$is an integer between$1$and$N$, inclusive. - For each integer
$i$($1 \leq i \leq N$), there is no position in$x$where$i$appears$i+1$or more times in a row.
翻译中…
You are given an integer sequence $A=(A_1,A_2,\cdots,A_N)$ of length $N$. Each element of $A$ is $-1$ or an integer between $1$ and $N$. Find the number, modulo $998244353$, of good sequences that can be obtained by replacing each $-1$ in $A$ with an integer between $1$ and $N$.
翻译中…
Constraints
翻译中…
$1 \leq N \leq 5000$$A_i=-1$or$1 \leq A_i \leq N$.- All input values are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
A_1 A_2 \cdots A_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
2
-1 -1
Output #1
3
You can obtain four sequences by replacing each $-1$ with an integer between $1$ and $2$.
$A=(1,1)$ is not a good sequence because $1$ appears twice in a row.
The other sequences $A=(1,2),(2,1),(2,2)$ are good.
Thus, the answer is $3$.
Input #2
3
2 -1 2
Output #2
2
Input #3
4
-1 1 1 -1
Output #3
0
Input #4
20
9 -1 -1 -1 -1 -1 -1 -1 -1 -1 7 -1 -1 -1 19 4 -1 -1 -1 -1
Output #4
128282166
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。