#C10864. Matrix Permutation

    ID: 40116 Type: Default 1000ms 256MiB

Matrix Permutation

Matrix Permutation

You are given a matrix of size \(n \times m\) and a permutation list containing \(n \times m\) integers. Your task is to produce a new matrix by reordering the elements of the input matrix using the given permutation.

The matrix is given in row-major order. The permutation list is 1-indexed, meaning that if an element in the permutation list is \(k\), it refers to the \(k^{th}\) element of the original matrix when it is flattened into a one-dimensional array. The output should be constructed by taking the elements in the order specified by the permutation list and then reshaping them into a matrix of size \(n \times m\).

Example:

Input:
3 4
1 2 3 4
5 6 7 8
9 10 11 12
7 10 5 8 1 2 3 4 11 12 9 6

Output: 7 10 5 8 1 2 3 4 11 12 9 6

</p>

inputFormat

The first line contains two integers \(n\) and \(m\) which represent the number of rows and columns of the matrix, respectively.

The next \(n\) lines each contain \(m\) integers representing the rows of the matrix.

The last line contains \(n \times m\) integers representing the permutation order. The permutation is 1-indexed.

outputFormat

Output the permuted matrix in \(n\) lines, where each line contains \(m\) space-separated integers.

## sample
3 4
1 2 3 4
5 6 7 8
9 10 11 12
7 10 5 8 1 2 3 4 11 12 9 6
7 10 5 8

1 2 3 4 11 12 9 6

</p>