AtCoder Regular Contest 187
B
Sum of CC
AtCoder
⌀ 2026
原题
← AC →
翻译中…

Problem Statement

翻译中…

For a sequence $A = (A_1, \ldots, A_N)$ of length $N$, define $f(A)$ as follows.

翻译中…
  • Prepare a graph with $N$ vertices labeled $1$ to $N$ and zero edges. For every integer pair $(i, j)$ satisfying $1 \leq i < j \leq N$, if $A_i \leq A_j$, draw a bidirectional edge connecting vertices $i$ and $j$. Define $f(A)$ as the number of connected components in the resulting graph.
翻译中…

You are given a sequence $B = (B_1, \ldots, B_N)$ of length $N$. Each element of $B$ is $-1$ or an integer between $1$ and $M$, inclusive.

翻译中…

By replacing every occurrence of $-1$ in $B$ with an integer between $1$ and $M$, one can obtain $M^q$ sequences $B'$, where $q$ is the number of $-1$ in $B$.

翻译中…

Find the sum, modulo $998244353$, of $f(B')$ over all possible $B'$.

翻译中…

Constraints

翻译中…
  • All input numbers are integers.
  • $2 \leq N \leq 2000$
  • $1 \leq M \leq 2000$
  • Each $B_i$ is $-1$ or an integer between $1$ and $M$, inclusive.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
B_1 \ldots B_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 3
2 -1 1
Output #1
6
There are three possible sequences $B'$: $(2,1,1)$, $(2,2,1)$, and $(2,3,1)$. When $B' = (2,1,1)$, an edge is drawn only between vertices $2$ and $3$, so the number of connected components is $2$. Thus, $f(B') = 2$. Similarly, $f(B') = 2$ for $B' = (2,2,1)$ and $f(B') = 2$ for $B' = (2,3,1)$, so the answer is $2 + 2 + 2 = 6$.
Input #2
10 8
-1 7 -1 -1 -1 2 -1 1 -1 2
Output #2
329785
Input #3
11 12
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Output #3
529513150
Remember to find the sum modulo $998244353$.
题目信息
题号
arc187_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。