| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 512 MB | 25 | 13 | 11 | 73.333% |
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