AtCoder Regular Contest 132
翻译中…
Problem Statement
翻译中…
Given is a sequence $a_1,\dots,a_n$ consisting of $1,\dots, n$ and $-1$, along with an integer $d$. How many sequences $p_1,\dots,p_n$ satisfy the conditions below? Print the count modulo $998244353$.
翻译中…
$p_1,\dots,p_n$is a permutation of$1,\dots, n$.- For each
$i=1,\dots,n$,$a_i=p_i$if$a_i\neq -1$. (That is,$p_1,\dots,p_n$can be obtained by replacing the$-1$s in$a_1,\dots,a_n$in some way.) - For each
$i=1,\dots,n$,$|p_i - i|\le d$.
翻译中…
Constraints
翻译中…
$1 \le d \le 5$$d < n \le 500$$1\le a_i \le n$or$a_i=-1$.$|a_i-i|\le d$if$a_i\neq -1$.$a_i\neq a_j$, if$i\neq j$and$a_i, a_j \neq -1$.- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
n d
a_1 \dots a_n
翻译中…
Output
翻译中…
Print the number of sequences that satisfy the conditions, modulo $998244353$.
翻译中…
样例
Input #1
4 2
3 -1 1 -1
Output #1
2
The conditions are satisfied by $(3,2,1,4)$ and $(3,4,1,2)$.
Input #2
5 1
2 3 4 5 -1
Output #2
0
The only permutation of $1,2,3,4,5$ that can be obtained by replacing the $-1$ is $(2,3,4,5,1)$, whose fifth term violates the condition, so the answer is $0$.
Input #3
16 5
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Output #3
794673086
Print the count modulo $998244353$.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。