HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > SEM 2 - W3 > problem:


2013-05-20. 50592 - Matrix Multiplication

SEM 2 - W3

Start: Mar.21.2023 at 04:30:12 PM
Finish: Mar.27.2023 at 08:30:12 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 2013-05-20. 50592 - Matrix Mul...
• 3rd-1. 50434 - Row Min Subtraction

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Matrix Multiplication

Shqip

Mr. Erjon is a mathematician. In many cases, he needs to multiply matrices with other matrices.

When multiplying two matrices, the left matrix rows are multiplied with the right matrix columns. Every left row element is multiplied with every right column element and then summed up. For example, when the first row and the second column elements are multiplied and summed, the result is placed to the first row and the second column in the resulting matrix. Thus, inner dimensions must be the same. And, the outer dimensions are the dimensions of the resulting matrice.

According to the figure on the right:

  • Matrix A has 4 rows and 2 columns;
  • Matrix B has 2 rows and 3 columns;
  • Thus, matrix res will have 4 rows and 3 columns;
Then, the matrix multiplication for every row and column element of the resulting array will be carried out as follows:
   res11 = (a11, a12)*(b11, b21) = (a11.b11) + (a12.b21)
   res12 = (a11, a12)*(b12, b22) = (a11.b12) + (a12.b22)
      .       .
      .       .
   res33 = (a31, a32)*(b13, b23) = (a31.b13) + (a32.b23)
      .       .
      .       .
      .       .

Question:
To help Mr. Erjon, write a program that is going to receive two 2D matrices and multiply them.

Input specification
First, you will be given three integers: m, n and k where the first matrix has m rows and n columns, and the second matrix has n rows and k columns and 1 < m, n , k ≤ 100. The following m rows contain n integers and for the first matrix, and then, the following n rows contain k integers for the second matrix. Matrix elements are positive integers that are less than 7000 and thus the results are in integer limits.

Output specification
Give m rows and k columns of integer numbers that represent the resulting matrix.

Sample Input I
  2 3 2
  3 4 2
  1 0 1
  1 4
  2 0
  4 4
Sample Output I  
  19 20
  5 8
 Sample Input II
  3 2 3
  1 4
  2 0
  4 4
  3 4 2
  1 0 1
 Sample Output II
  7 4 6
  6 8 4
  16 16 12

Для отправки решений необходимо выполнить вход.

www.contester.ru