시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 18 | 12 | 10 | 71.429% |
Consider two permutations of integers from $1$ to $n$: $p$ and $q$. Let us call a binary string $s$ of length $n$ satisfying if there exists a matrix $a$ with dimensions $2 \times n$ such that:
0
.For two permutations $p$ and $q$ of size $n$, let us define $f(p, q)$ as the number of satisfying strings $s$ for them.
You are given all elements of $p$, and several elements of $q$, but forgot others. Find the sum of $f(p, q)$ over all permutations $q$ with the given known elements, modulo $998\,244\,353$.
The first line of the input contains a single integer $n$ ($1 \le n \le 100$).
The second line of the input contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$, all $p_i$ are distinct), a permutation of numbers from $1$ to $n$.
The second line of the input contains $n$ integers $q_1, q_2, \ldots, q_n$ ($0 \le q_i \le n$, $q_i \neq q_j$ when $q_i \neq 0$ and $q_j \neq 0$). If $q_i \neq 0$, the respective element is given. If $q_i = 0$, its value is forgotten. All given elements are distinct.
Output the sum of $f(p, q)$ over all valid permutations $q$ modulo $998\,244\,353$.
2 1 2 2 1
3
4 4 3 2 1 4 3 2 1
16
5 1 2 3 4 5 0 0 0 0 0
1546
6 1 6 2 5 3 4 0 1 0 2 0 3
52