#C8833. Matrix Multiplication

    ID: 52859 Type: Default 1000ms 256MiB

Matrix Multiplication

Matrix Multiplication

You are given two matrices A and B in flattened form along with their dimensions. Your task is to perform matrix multiplication and output the resulting matrix.

Let matrix A be of dimension \(r_1 \times c_1\) and matrix B be of dimension \(r_2 \times c_2\). It is guaranteed that \(c_1 = r_2\). The product matrix C will then have dimensions \(r_1 \times c_2\) and each element is computed as follows:

[ C_{ij} = \sum_{k=1}^{c_1} A_{ik} \times B_{kj} ]

Read the matrices from standard input and print the output to standard output.

inputFormat

The input is given via standard input and has the following format:

  • The first line contains two integers \(r_1\) and \(c_1\) representing the number of rows and columns of matrix A.
  • The second line contains \(r_1 \times c_1\) integers representing the elements of matrix A in row-major order.
  • The third line contains two integers \(r_2\) and \(c_2\) representing the number of rows and columns of matrix B.
  • The fourth line contains \(r_2 \times c_2\) integers representing the elements of matrix B in row-major order.

It is guaranteed that \(c_1 = r_2\) so that the matrix product is well-defined.

outputFormat

Output the resulting matrix C to standard output. Each row of the matrix should be printed on a separate line with the elements separated by a single space.

## sample
2 2
1 2 3 4
2 2
5 6 7 8
19 22

43 50

</p>