問題一覧 > 通常問題

No.2405 Minimal Matrix Decomposition

レベル : / AI推定難易度 : 1675 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 21
作問者 : 👑 獅子座じゃない人 / テスター : 👑 amentorimaru
お気に入りにしたユーザー ProblemId : 9948 / 自分の提出
問題文最終更新日: 2023-08-03 22:04:08
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 400 (順位表) の他の問題:

Problem Statement

You are given a prime $P$, positive integers $N,M$, and an $N\times M$ matrix $A$. The entries of $A$ satisfy $0\leq A_{ij}\lt P\ (1\leq i\leq N,\ 1\leq j\leq M)$.

Rueru is trying to memorize the matrix $A$, and in order to reduce the number of entries to memorize, he has decided to decompose $A$ into a product of multiple matrices.

Consider a non-empty sequence of matrices $(B^{(1)},\ B^{(2)},\ \ldots,\ B^{(L)})$ of length $L\ (L\geq 1)$, where $B^{(k)}$ is an $N_k\times M_k$ matrix $(1\leq k\leq L)$. $L=1$ is allowed, $0\leq B_{ij}^{(k)}\lt P\ (1\leq k\leq L,\ 1\leq i\leq N_k,\ 1\leq j\leq M_k)$ must hold, and addition and multiplication of entries are performed modulo $P$.

Among the sequences satisfying $A=B^{(1)}B^{(2)}\ldots B^{(L)}$, find $1$ example of a sequence that minimizes $\sum_{k=1}^L N_kM_k$. For the output format, refer to the "Output" block.

Input

$P$
$N\ M$
$A_{11}\ A_{12}\ A_{13}\ \ldots\ A_{1M}$
$A_{21}\ A_{22}\ A_{23}\ \ldots\ A_{2M}$
$A_{31}\ A_{32}\ A_{33}\ \ldots\ A_{3M}$
$\vdots$
$A_{N1}\ A_{N2}\ A_{N3}\ \ldots\ A_{NM}$

  • All inputs are integers
  • $P$ is a prime
  • $2\leq P\leq 10^9$
  • $1\leq N\leq 400$
  • $1\leq M\leq 400$
  • $0\leq A_{ij}\lt P\ (1\leq i\leq N,\ 1\leq j\leq M)$

Output

$L$
$N_1\ M_1$
$B_{11}^{(1)}\ B_{12}^{(1)}\ B_{13}^{(1)}\ \ldots\ B_{1M_1}^{(1)}$
$B_{21}^{(1)}\ B_{22}^{(1)}\ B_{23}^{(1)}\ \ldots\ B_{2M_1}^{(1)}$
$B_{31}^{(1)}\ B_{32}^{(1)}\ B_{33}^{(1)}\ \ldots\ B_{3M_1}^{(1)}$
$\vdots$
$B_{N_11}^{(1)}\ B_{N_12}^{(1)}\ B_{N_13}^{(1)}\ \ldots\ B_{N_1M_1}^{(1)}$
$N_2\ M_2$
$B_{11}^{(2)}\ B_{12}^{(2)}\ B_{13}^{(2)}\ \ldots\ B_{1M_2}^{(2)}$
$B_{21}^{(2)}\ B_{22}^{(2)}\ B_{23}^{(2)}\ \ldots\ B_{2M_2}^{(2)}$
$B_{31}^{(2)}\ B_{32}^{(2)}\ B_{33}^{(2)}\ \ldots\ B_{3M_2}^{(2)}$
$\vdots$
$B_{N_21}^{(2)}\ B_{N_22}^{(2)}\ B_{N_23}^{(2)}\ \ldots\ B_{N_2M_2}^{(2)}$
$\vdots$
$N_L\ M_L$
$B_{11}^{(L)}\ B_{12}^{(L)}\ B_{13}^{(L)}\ \ldots\ B_{1M_L}^{(L)}$
$B_{21}^{(L)}\ B_{22}^{(L)}\ B_{23}^{(L)}\ \ldots\ B_{2M_L}^{(L)}$
$B_{31}^{(L)}\ B_{32}^{(L)}\ B_{33}^{(L)}\ \ldots\ B_{3M_L}^{(L)}$
$\vdots$
$B_{N_L1}^{(L)}\ B_{N_L2}^{(L)}\ B_{N_L3}^{(L)}\ \ldots\ B_{N_LM_L}^{(L)}$

First print $L$, then print $N_k,\ M_k$ and the entries of $B^{(k)}$ $(1\leq k\leq L)$ in order.

Your output must satisfy $0\leq B_{ij}^{(k)}\lt P\ (1\leq k\leq L,\ 1\leq i\leq N_k,\ 1\leq j\leq M_k)$, and print a newline at the end.

Sample

Sample 1
Input
998244353
5 4
21 17 13 9
18 16 14 12
15 15 15 15
12 14 16 18
9 13 17 21
Output
2
5 2
1 5
2 4
3 3
4 2
5 1
2 4
1 2 3 4
4 3 2 1

$\begin{pmatrix}1&5\\2&4\\3&3\\4&2\\5&1\end{pmatrix}\begin{pmatrix}1&2&3&4\\4&3&2&1\end{pmatrix}=\begin{pmatrix}21&17&13&9\\18&16&14&12\\15&15&15&15\\12&14&16&18\\9&13&17&21\end{pmatrix}$ holds. Also, $\sum_{k=1}^L N_kM_k=5\cdot 2+2\cdot 4=18$, and $\sum_{k=1}^L N_kM_k$ cannot be made smaller than $18$.

Sample 2
Input
5
2 2
1 2
3 4
Output
1
2 2
1 2
3 4

There are also cases where $L=1$.

Sample 3
Input
7
3 4
2 3 4 5
4 6 1 3
6 2 5 1
Output
2
3 1
1
2
3
1 4
2 3 4 5

Note that addition and multiplication of entries are performed modulo $P$.

Sample 4
Input
998244353
3 3
0 0 0
0 0 0
0 0 0
Output
2
3 1
0
0
0
1 3
0 0 0

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。