(Long problem statement incoming!)
In this problem, we introduce two objects in linear algebra: vectors and matrices. Here, we will interpret a vector as a 1D array and a matrix as a 2D array. In actuality, they carry some mathematical meaning beyond their structure.
A vector $\mathbf{v}$ can be represented by its coordinates: $\mathbf{v} = (v_1, v_2, \cdots, v_n)$.
Let's first define the dot product of two vectors. Given two vectors $\mathbf{a} = (a_1, a_2, \cdots, a_n)$ and $\mathbf{b} = (b_1, b_2, \cdots, b_n)$, the dot product $\mathbf{a} \cdot \mathbf{b}$ is computed as $$\mathbf{a} \cdot \mathbf{b} = (a_1b_1, a_2b_2, \cdots, a_nb_n)$$
A matrix is a rectangular array of numbers. For example, $A$ is a $3 \times 4$ matrix, where the $a_{ij}$ is the entry on the $i$'th row and $j$'th column.
$$A = \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \end{bmatrix}$$Here is another $4 \times 2$ matrix $B$:
$$B = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ b_{31} & b_{32} \\ b_{41} & b_{42} \end{bmatrix}$$If matrix $A$ has dimension $n \times k$ and matrix $B$ has dimension $k \times m$, we can multiply them to obtain $C = AB$, a $n \times m$ matrix. Write $C = [c_{ij}]$, then $c_{ij}$ is defined to be:
$$c_{ij} = a_{i1} b_{1j} + a_{i2} b_{2j} + \cdots + a_{ik} b_{kj}$$i.e., $c_{ij}$ is the dot product of the $i$'th row in $A$ and the $j$'th column in $B$.
Giving concrete values to the entries of $A$ and $B$, the product $C = AB$ is as follows:
$$ \underset{A}{\begin{bmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \end{bmatrix}} \underset{B}{\begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \\ 7 & 8 \end{bmatrix}} = \underset{C}{\begin{bmatrix} 50 & 60 \\ 114 & 140 \\ 178 & 220 \end{bmatrix}} $$where
$$\begin{align*} c_{11} &= (1)(1) + (2)(3) + (3)(5) + (4)(7) \\ c_{32} &= (9)(2) + (10)(4) + (11)(6) + (12)(8) \end{align*}$$Now, given a matrix $A$ of dimension $n \times k$ and another matrix $B$ of dimension $k \times m$, find the product $C = AB$.
Input
The first line of input contains 3 integers $n$, $k$ and $m$.
The next $n$ lines contain the entries of $A$.
The next $k$ lines contain the entries of $B$.
Output
Output the product $C = AB$ in the same format as given in the input.
Constraints
For all subtasks, $1 \le n, m, k \le 100$ and $-500 \le a_{ij}, b_{ij} \le 500$.
Subtask 1: $n = m = k$ (30%)
Subtask 2: No additional constraints (70%)
Sample Test Cases
Input | Output | |
---|---|---|
3 3 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
84 90 96 201 216 231 318 342 366 |
|
This sample satisfies the constraints of subtask 1. | ||
3 4 2 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 |
50 60 114 140 178 220 |
Scoring: Per Subtask
Authored by s16f22
Appeared in 2024 Mini Contest 1