estie プログラミングコンテスト2024 (AtCoder Regular Contest 188)
D
Mirror and Order
AtCoder
⌀ 3178
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are going to create $N$ sequences of length $3$, satisfying the following conditions.

翻译中…
  • For each of $k = 1,2,3$, the following holds:
  • Among the $k$-th elements of the sequences, each integer from $1$ through $N$ appears exactly once.
翻译中…

For this sequence of sequences, define sequences $a=(a_1,a_2,\ldots,a_N)$ and $b=(b_1,b_2,\ldots,b_N)$ as follows.

翻译中…
  • Let $s_i$ be the $i$-th sequence, and let $t_i$ be the reverse of the $i$-th sequence. When all of these are sorted in lexicographical order, $s_i$ comes $a_i$-th, and $t_i$ comes $b_i$-th.
  • Here, if there are identical sequences among the $2N$ sequences, $a$ and $b$ are not defined.
翻译中…

Therefore, if $a$ and $b$ are defined, each integer from $1$ through $2N$ appears exactly once in the concatenation of $a$ and $b$.

翻译中…

You are given sequences $A$ and $B$ of length $N$, where each element of $A$ is an integer between $1$ and $2N$, and each element of $B$ is either an integer between $1$ and $2N$ or $-1$. Also, in the concatenation of $A$ and $B$, each integer other than $-1$ appears at most once.

翻译中…

How many pairs of sequences $a,b$ are there such that $a$ and $b$ are defined and the following holds for each integer $i$ from $1$ through $N$?

翻译中…
  • $a_i = A_i$.
  • $b_i = B_i$ if $B_i \neq -1$.
翻译中…

Find the count modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 3000$
  • $1 \leq A_i \leq 2N$
  • $1 \leq B_i \leq 2N$ or $B_i = -1$.
  • In the concatenation of $A$ and $B$, each integer other than $-1$ appears at most once. That is,
  • $A_i \neq A_j$ if $i \neq j$.
    • $B_i \neq B_j$ if $i \neq j$ and $B_i,B_j \neq -1$.
    • $A_i \neq B_j$.
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

翻译中…

Output

翻译中…

Print the count modulo $998244353$.

翻译中…

样例

Input #1
3
2 3 6
-1 1 -1
Output #1
1
For example, consider creating the following three sequences: 1. $(1,2,3)$ 2. $(2,1,1)$ 3. $(3,3,2)$ In this case, when sorting $s_i$ and $t_i$ lexicographically, we have: > $t_2 = (1,1,2) < s_1 = (1,2,3) < s_2 = (2,1,1) < t_3 = (2,3,3) < t_1 = (3,2,1) < s_3 = (3,3,2)$ Thus, $(a_1,a_2,a_3,b_1,b_2,b_3) = (2,3,6,5,1,4)$. Here, $a$ matches the given $A$, and the second element of $b$ also matches that of $B$, so this is one pair of sequences $a,b$ satisfying the conditions. On the other hand, if we create the following three sequences, $s_1$ and $t_1$ become identical, so $a$ and $b$ are not defined. 1. $(1,2,1)$ 2. $(2,1,3)$ 3. $(3,3,2)$ In fact, $a=(2,3,6), b=(5,1,4)$ is the only pair of sequences satisfying the conditions.
Input #2
15
5 16 1 12 30 20 4 13 9 8 24 21 26 28 17
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 29 -1 -1 -1
Output #2
758094847
Print the count modulo $998244353$.
题目信息
题号
arc188_d
时间限制
2 s
内存限制
1024 MB

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