#P3890. [GDOI2014] 比特矩阵

[GDOI2014] 比特矩阵

Description

Due to the popularity of The Hobbit, L’s roommate X has recently become interested in the currency they use. For this study, X needs to understand something called a bit matrix. Although a bit matrix is still a matrix, its multiplication is a little different from ordinary matrix multiplication.

For bit matrices, C=A×BC = A \times B means ci,j=Vk=1naikbkjc_{i, j} = V_{k=1}^{n} a_{i k} \bigoplus b_{k j}. Here VV denotes taking bitwise OR over a sequence; for example, Vi=1niV_{i=1}^{n} i means 12n1 \mid 2 \mid \cdots \mid n. The symbol \mid means bitwise OR. Bitwise OR views two numbers in binary: if at bit ii at least one of the two numbers is 11, then the ii-th bit of the result is 11; otherwise that bit is 00. The symbol \bigoplus denotes bitwise XOR: if the ii-th bits of two binary numbers are different, then the ii-th bit of the result is 11; otherwise it is 00.

Here is an example of bit-matrix multiplication.

$$\begin{bmatrix}1&6\\3&5\end{bmatrix}\times\begin{bmatrix}3&6\\5&7\end{bmatrix}=\begin{bmatrix}3&7\\0&7\end{bmatrix}$$

Now X would like you to compute AmA^{m}, where AA is an n×nn \times n bit matrix, and AmA^{m} is the result of multiplying mm copies of AA. Precisely:

  • A1=AA^{1} = A.
  • Am=Am1×AA^{m} = A^{m-1} \times A, for m>1m > 1.

Input Format

The first line contains two positive integers n,mn, m. The next nn lines each contain nn non-negative integers; in these nn lines, the jj-th number of the ii-th line is the element ai,ja_{i, j} of the bit matrix.

Output Format

Output the bit matrix AmA^{m}. That is, print a bit matrix in the same format as the input matrix AA. See the sample output for details.

2 4
10 5
5 10

0 15
15 0

3 16
6 5 7
5 6 7
7 7 6

0 3 3
3 0 3
3 3 0

Hint

Constraints

  • For 10%10\% of the testdata, n4n \le 4, m10000m \le 10000.
  • For 30%30\% of the testdata, n10n \le 10, m109m \le 10^9.
  • For 100%100\% of the testdata, n500n \le 500, m109m \le 10^9, and all input integers do not exceed 10910^9.

Translated by ChatGPT 5