#P8544. 「Wdoi-2」禁断之门对面,是此世还是彼世
「Wdoi-2」禁断之门对面,是此世还是彼世
Background
Perhaps because the Land of the Back Door rarely contacts the outside world, perhaps due to limits of her divine duties, or perhaps simply because of personal preference, as one of the sages who first built Gensokyo, Matara does not interact frequently with the other sages. Other sages such as Yakumo Yukari and Ibaraki Kasen all walk within Gensokyo in person, but Matara stays outside it.
Spending divine power to trigger an incident on the scale of the whole Gensokyo may look huge, but in fact it caused no real damage to Gensokyo, only making a group of foolish fairies more irritable.
No one knows what the secret god behind the door is truly thinking.
Problem Description
You are given a positive integer sequence of length and a positive integer sequence of length .
Now Lan constructs an -row, -column positive integer matrix from sequences and , satisfying . You need to construct a positive integer matrix with rows and columns, satisfying the following conditions:
- Each element of the matrix is in .
- Elements in the same row of the matrix are pairwise distinct.
- Adjacent elements in each column of the matrix are different.
- Among all matrices that satisfy the above three requirements, minimize:
Output the value of modulo for the constructed matrix .
Input Format
The first line contains three integers .
The next line contains integers , as described in the statement.
The next line contains integers , as described in the statement.
Output Format
Output one line, representing the value of modulo for the constructed matrix .
2 2 2
9 9
6 1
252
10 10 10
2 8 10 10 10 2 5 8 9 3
2 1 5 2 10 7 8 9 10 6
8040
Hint
Sample Explanation 1
According to the statement, we can construct .
You need to construct a -row, -column matrix $B=\begin{bmatrix}1 & 2 \\ 2 & 1 \\ 1 & 2 \end{bmatrix}$. In this case, is the minimum.
It can be proven that among all cases, the minimum value of is .
Constraints and Notes
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|}\hline \textbf{Subtask} & \bm{n \le } & \bm{m \le } & \bm{t \le } & \textbf{特殊性质} & \textbf{分值}\\\hline 1 & 10 & 10 & 10 & - & 5 \\\hline 2 & 100 & 100 & 100 & - & 5 \\\hline 3 & 10^3 & 10^3 & 10^3 & - & 15 \\\hline 4 & 5\times 10^4 & 5\times 10^4 & 5\times 10^4 & - & 30 \\\hline 5 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & \textbf{A} & 10 \\\hline 6 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & \textbf{B} & 10 \\\hline 7 & 5\times 10^5 & 5\times 10^5 & 5\times 10^5 & - & 25 \\\hline \end{array}$$- Special Property : It is guaranteed that .
- Special Property : It is guaranteed that .
For all testdata, it is guaranteed that , and . It is guaranteed that a solution exists.
Translated by ChatGPT 5