Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Little Matrix Multiplication

Limits 1s, 512 MB

Given two 2×22\times2 matrices, calculate the product of the two matrices.

The product of two 2×22\times2 matrices will produce another 2×22\times2 matrix where:

A = [ A₁₁ A₁₂
      A₂₁ A₂₂ ]
B = [ B₁₁ B₁₂
      B₂₁ B₂₂ ]
C = A × B = [ C₁₁ C₁₂
              C₂₁ C₂₂ ]
C₁₁ = A₁₁ ×  B₁₁ + A₁₂ × B₂₁
C₁₂ = A₁₁ ×  B₁₂ + A₁₂ × B₂₂
C₂₁ = A₂₁ ×  B₁₁ + A₂₂ × B₂₁
C₂₂ = A₂₁ ×  B₁₂ + A₂₂ × B₂₂

For example:

A = [ 2 3
      4 5 ]
B = [ 5 6
      7 8 ]
C = A × B = [ 31 36
              55 64 ]

Input

The input contains two matrices as follows:

A₁₁ A₁₂
A₂₁ A₂₂
B₁₁ B₁₂
B₂₁ B₂₂

The value of each of these 8 integers is non-negative and less than 100.

Output

Print the product of the two matrices as follows:

C₁₁ C₁₂
C₂₁ C₂₂

Sample

InputOutput
2 3
4 5
5 6
7 8
31 36
55 64

Discussion

Statistics


99% Solution Ratio

YouKnowWhoEarliest, Mar '19

YouKnowWhoFastest, 0.0s

N550999.Lightest, 0 B

abdullahalkafiShortest, 110B

Submit

Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.