AtCoder Regular Contest 190 (Div. 1)
D
Matrix Pow Sum
AtCoder
⌀ 2802
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given a prime number $p$ and an $N \times N$ matrix $A = (A_{i,j})$ ($1\leq i,j\leq N$). Each element of $A$ is an integer between $0$ and $p-1$, inclusive.

翻译中…

Consider a matrix $B$ obtained by replacing each zero in $A$ with an integer between $1$ and $p-1$, inclusive. There are $(p-1)^K$ such matrices $B$, where $K$ is the number of zeros in $A$.

翻译中…

Find each element, modulo $p$, of the sum of $B^p$ over all possible $B$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 100$
  • $p$ is a prime such that $1 \leq p \leq 10^9$.
  • $0 \leq A_{i,j} \leq p-1$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N p
A_{1,1} \cdots A_{1,N}
\vdots
A_{N,1} \cdots A_{N,N}

翻译中…

Output

翻译中…

Print $N$ lines.

翻译中…

The $i$-th line should contain, in the order $j=1,\ldots,N$, the $(i,j)$ element of the sum, modulo $p$, of $B^p$ over all possible $B$, separated by spaces.

翻译中…

样例

Input #1
2 3
0 1
0 2
Output #1
0 2
1 2
$B^p$ for all possible $B$ are as follows: - $\begin{pmatrix}1&1 \\ 1&2\end{pmatrix}^3=\begin{pmatrix}5&8 \\ 8&13\end{pmatrix}$ - $\begin{pmatrix}1&1 \\ 2&2\end{pmatrix}^3=\begin{pmatrix}9&9 \\ 18&18\end{pmatrix}$ - $\begin{pmatrix}2&1 \\ 1&2\end{pmatrix}^3=\begin{pmatrix}14&13 \\ 13&14\end{pmatrix}$ - $\begin{pmatrix}2&1 \\ 2&2\end{pmatrix}^3=\begin{pmatrix}20&14 \\ 28&20\end{pmatrix}$ Print each element, modulo $p=3$, of their sum $\begin{pmatrix}48&44 \\ 67&65\end{pmatrix}$.
Input #2
3 2
1 0 0
0 1 0
0 0 1
Output #2
1 1 1
1 1 1
1 1 1
$B^p$ for all possible $B$ are as follows: - $\begin{pmatrix}1&1&1 \\ 1&1&1 \\ 1&1&1\end{pmatrix}^2=\begin{pmatrix}3&3&3\\3&3&3\\3&3&3\end{pmatrix}$ Print each element, modulo $p=2$, of their sum $\begin{pmatrix}3&3&3\\3&3&3\\3&3&3\end{pmatrix}$.
Input #3
4 13
0 1 2 0
3 4 0 5
0 6 0 7
8 9 0 0
Output #3
8 0 6 5
11 1 8 5
8 0 4 12
8 0 1 9
题目信息
题号
arc190_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。