2 2 0 0 1 2
4
The four matrices that satisfy the conditions are:
$\begin{pmatrix}0&0\\1&2\end{pmatrix}$, $\begin{pmatrix}0&0\\2&1\end{pmatrix}$, $\begin{pmatrix}1&2\\0&0\end{pmatrix}$, $\begin{pmatrix}2&1\\0&0\end{pmatrix}$.
We can verify that $\begin{pmatrix}2&1\\0&0\end{pmatrix}$, for example, satisfies the conditions as follows.
* Performing row-sort and then column-sort: $\begin{pmatrix}2&1\\0&0\end{pmatrix}\to \begin{pmatrix}1&2\\0&0\end{pmatrix} \to \begin{pmatrix}0&0\\1&2\end{pmatrix}$.
* Performing column-sort and then row-sort:$\begin{pmatrix}2&1\\0&0\end{pmatrix}\to \begin{pmatrix}0&0\\2&1\end{pmatrix} \to \begin{pmatrix}0&0\\1&2\end{pmatrix}$.3 3 0 1 3 2 4 7 5 6 8
576
$\begin{pmatrix}5&7&6\\3&0&1\\4&8&2\end{pmatrix}$, for example, satisfies the conditions, which can be verified as follows.
* Performing row-sort and then column-sort: $\begin{pmatrix}5&7&6\\3&0&1\\4&8&2\end{pmatrix}\to \begin{pmatrix}5&6&7\\0&1&3\\2&4&8\end{pmatrix} \to \begin{pmatrix}0&1&3\\2&4&7\\5&6&8\end{pmatrix}$.
* Performing column-sort and then row-sort: $\begin{pmatrix}5&7&6\\3&0&1\\4&8&2\end{pmatrix}\to \begin{pmatrix}3&0&1\\4&7&2\\5&8&6\end{pmatrix} \to \begin{pmatrix}0&1&3\\2&4&7\\5&6&8\end{pmatrix}$.3 5 0 0 0 1 1 0 0 1 1 2 0 1 1 2 2
10440
1 7 2 3 3 6 8 8 9
1260
{
"problem": {
"name": "RowCol/ColRow Sort",
"description": {
"content": "Consider the following operations on an $H\\times W$ matrix $A = (A_{i,j})$ ($1\\leq i\\leq H, 1\\leq j\\leq W$). * **Row-sort**: Sort every row in ascending order. That is, sort $A_{i,1},\\ldots,A_{i,W}",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 3000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "agc057_e"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Consider the following operations on an $H\\times W$ matrix $A = (A_{i,j})$ ($1\\leq i\\leq H, 1\\leq j\\leq W$).\n\n* **Row-sort**: Sort every row in ascending order. That is, sort $A_{i,1},\\ldots,A_{i,W}...",
"is_translate": false,
"language": "English"
}
]
}