Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Matrix Multiplication

Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:

\[
c_{ij} = \sum_{k=1}^m a_{ik}b_{kj}
\]

  where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.

Input

  In the first line, three integers $n$, $m$ and $l$ are given separated by space characters

  In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.

Output

  Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.

Constraints

$1 \leq n, m, l \leq 100$

$0 \leq a_{ij}, b_{ij} \leq 10000$

Sample Input

3 2 3
1 2
0 3
4 5
1 2 1
0 3 2

Sample Output

1 8 5
0 9 6
4 23 14

Note

      解説      

	



Sample input:
3 2 3
1 2
0 3
4 5
1 2 1
0 3 2


Sample output:
1 8 5
0 9 6
4 23 14

Submission status: WA: Presentation Error

Solution code:
n,m,l = map(int,input().split())
A = [[int(i) for i in input().split()] for j in range(n)]
B = [[int(i) for i in input().split()] for j in range(m)]
C = [[0 for i in range(n)] for k in range(l)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k]*B[k][j]
cnt=0
for i in range(n):
    for j in C[i]:
        cnt += 1
        if i == n-1 and cnt == n*l:
            print(j,end="")
        else:
            print(j,end=" ")
    print()

Submission status: WA: Presentation Error

Solution code:
A = []
B = []
C = []
n, m, l = map(int, input().strip().split())
[A.append(list(map(int, input().strip().split()))) for x in range(n)]
[B.append(list(map(int, input().strip().split()))) for y in range(m)]
[C.append([0 for zz in range(l)]) for z in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k]*B[k][j]
        print(C[i][j],end=' ')
    print()

Submission status: WA: Presentation Error

Solution code:
n,m,l = [int(x) for x in input().split()]
matrix_a = [[int(x) for x in input().split()] for _ in range(n)]
matrix_b = [[int(x) for x in input().split()] for _ in range(m)]
matrix_ab = [[0 for a in range(l)] for b in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            matrix_ab[i][j] += matrix_a[i][k]*matrix_b[k][j]
for i in range(n):
    for j in range(l):
            print(matrix_ab[i][j], "", end="")
    print()

Submission status: WA: Presentation Error

Solution code:
n,m,l = [int(i) for i in input().split()]
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
for i in range(n):
	a[i] = [int(j) for j in input().split()]
for i in range(m):
	b[i] = [int(j) for j in input().split()]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
	for j in range(l):
		for k in range(m):
			c[i][j] += a[i][k] * b[k][j]
		print(c[i][j],end=' ')
	print()

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
# Here your code !
 
def func():
    try:
        (n,m,l) = [ int(item) for item in input().rstrip().split(" ") ]
        matrix_A = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(n) ]
        matrix_B = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(m) ]
    except:
        return inputError()
        
    matrix_C = [ [ sum([ matrix_A[i][j]*matrix_B[j][k] for j in range(m) ]) for k in range(l) ] for i in range(n) ]
    result=""

    for vector in matrix_C:
        for item in vector:
            result+=str(item)+" "
        result.rstrip()
        result+="\n"
    print(result.rstrip())

def inputError():
    '''
    print("input Error")
    return -1
    '''
 
    print("input Error")
    return -1
     
func()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int, raw_input().split())

A, B = [], []
for ni in range(n):
    A.append(map(int, raw_input().split()))

for mi in range(m):
    B.append(map(int, raw_input().split()))

_B = list(map(list, zip(*B)))

for a in A:
    for b in _B:
        result = 0
        for i, j in zip(a, b):
            result += i*j
        print "%d" % result, 
    print "\n",

Submission status: WA: Presentation Error

Solution code:
I = input().split()
n = int(I[0])
m = int(I[1])
l = int(I[2])

a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]
c = [[0 for i2 in range(l)] for i1 in range(n)]

for i in range(n):
    A = input().split()
    for j in range(m):
        a[i][j] = int(A[j])

for i in range(m):
    B = input().split()
    for j in range(l):
        b[i][j] = int(B[j])

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
        print(str(c[i][j]), end = '')
        if i != n - 1 or j != l - 1:
            print(' ', end = '')
    print()

Submission status: WA: Presentation Error

Solution code:
I = input().split()
n = int(I[0])
m = int(I[1])
l = int(I[2])

a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]
c = [[0 for i2 in range(l)] for i1 in range(n)]

for i in range(n):
    A = input().split()
    for j in range(m):
        a[i][j] = int(A[j])

for i in range(m):
    B = input().split()
    for j in range(l):
        b[i][j] = int(B[j])

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
        print(str(c[i][j]), end = '')
        if i != n - 1 or j != l - 1:
            print(' ', end = '')
    if i != n - 1 or j != l - 1:
        print()

Submission status: WA: Presentation Error

Solution code:
I = input().split()
n = int(I[0])
m = int(I[1])
l = int(I[2])

a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]
c = [[0 for i2 in range(l)] for i1 in range(n)]

for i in range(n):
    A = input().split()
    for j in range(m):
        a[i][j] = int(A[j])

for i in range(m):
    B = input().split()
    for j in range(l):
        b[i][j] = int(B[j])

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
        print(str(c[i][j]), end = '')
        if j != l - 1:
            print(' ', end = '')
    if i != n - 1 or j != l - 1:
        print()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int, input().split())
A, B = [list(map(int, input().split())) for r in range(n)], [list(map(int, input().split())) for r in range(m)]
for i in range(n):
    for j in range(l):
        Cij = 0
        for k in range(m):
            Cij += A[i][k]*B[k][j]
        print('%d' %(Cij), end=' ')
    print()

Submission status: WA: Presentation Error

Solution code:
import sys
s=input().split()
n=int(s[0]);m=int(s[1]);l=int(s[2])
a=[[0 for j in range(m)]for i in range(n)]
b=[[0 for j in range(l)]for i in range(m)]
c=[[0 for j in range(l)]for i in range(n)]
for i in range(n):
    t=input().split()
    for j in range(m):
        a[i][j]=int(t[j])
for i in range(m):
    t=input().split()
    for j in range(l):
        b[i][j]=int(t[j])
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j]+=a[i][k]*b[k][j]
        sys.stdout.write("{0} ".format(c[i][j]))
    sys.stdout.write("\n")

Submission status: WA: Presentation Error

Solution code:
n,m,l=map(int,input().split())
matrix_a=[]
matrix_b=[]
matrix_c=[]
for i in range(n):
    matrix_a.append(list(map(int,input().split())))
for i in range(m):
    matrix_b.append(list(map(int,input().split())))
tmp_l=list()
for i in range(n):
    for j in range(l):
        tmp_n=0
        for k in range(m):
            tmp_n+=matrix_a[i][k]*matrix_b[k][j]
        tmp_l.append(tmp_n)
    matrix_c.append(tmp_l.copy())
    tmp_l.clear()
for i in matrix_c:
    for j in i:
        print(j,"",end="")
    print()

Submission status: WA: Presentation Error

Solution code:
n,m,l=map(int,input().split())
matrix_a=[]
matrix_b=[]
matrix_c=[]
for i in range(n):
    matrix_a.append(list(map(int,input().split())))
for i in range(m):
    matrix_b.append(list(map(int,input().split())))
tmp_l=list()
for i in range(n):
    for j in range(l):
        tmp_n=0
        for k in range(m):
            tmp_n+=matrix_a[i][k]*matrix_b[k][j]
        tmp_l.append(tmp_n)
    matrix_c.append(tmp_l.copy())
    tmp_l.clear()
for i in matrix_c:
    for j in i:
        if i[-1]==j:
            print(j,end="")
        else:
            print(j,"",end="")
    print()

Submission status: WA: Presentation Error

Solution code:
import sys

(n, m, l) = sys.stdin.readline().rstrip('\r\n').split(' ')
n = int(n)
m = int(m)
l = int(l)

a = []
b = []
c = []
for ii in range(n):
  a.append([int(x) for x in input().rstrip('\r\n').split(' ')])

for ii in range(m):
  b.append([int(x) for x in input().rstrip('\r\n').split(' ')])

for ii in range(n):
  c.append([])
  for jj in range(l):
    c[ii].append(0)
    for kk in range(m):
      c[ii][jj] += a[ii][kk] * b[kk][jj]
    print(str(c[ii][jj]) + ' ', end='')
  print()

Submission status: WA: Presentation Error

Solution code:
class Matrix:
    def __init__(self, rows, cols, values=None):
        self.rows = rows 
        self.cols = cols 
        if values is not None:
            self.values = values
        else:
            row = [0 for i in range(cols)]
            self.values = [row[:] for j in range(rows)]

    def row(self, i):
        return self.values[i-1]

    def col(self, j):
        return [row[j-1] for row in self.values]

    def __mul__(self, other):
        assert self.cols == other.rows

        m = self.__class__(self.rows, other.cols)
        for i in range(self.rows):
            for j in range(other.cols):
                m[i, j] = sum(a * b for (a, b) in zip(self.row(i),
                                                      other.col(j)))
        return m

    def __getitem__(self, idx):
        row, col = idx   
        return self.values[row-1][col-1]

    def __setitem__(self, idx, val):
        row, col = idx   
        self.values[row-1][col-1] = val

    def __str__(self):   
        s = ""
        for row in self.values:
            s += " ".join([str(i) for i in row]) + "\n"
        return s


def run():
    n, m, l = [int(v) for v in input().split()]

    m1 = []
    for i in range(n):   
        m1.append([int(v) for v in input().split()])

    m2 = []
    for i in range(m):   
        m2.append([int(v) for v in input().split()])

    print(Matrix(n, m, m1) * Matrix(m, l, m2))


run()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for i in a:
  for j in zip(*b):
    print(sum([k * l for k, l in zip(i, j)]), end = " ")
  print("")

Submission status: WA: Presentation Error

Solution code:
# -*- coding: utf-8 -*-

n, m, l = list(map(int, input().split()))
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    for j in range(l):
        mat_sum = 0
        for k in range(m):
            mat_sum += a[i][k] * b[k][j]
        print('{0} '.format(mat_sum), end='')
    print()

Submission status: WA: Presentation Error

Solution code:
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
for c in e[1:n]:
    for l in zip(*e[n:]):
        print(sum(s*t for s,t in zip(c,l)),'',end='')
    print()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int, input().split())

m1 = [list(map(int, input().split())) for _ in range(n)]
m2 = [list(map(int, input().split())) for _ in range(m)]
m2 = list(map(list, zip(*m2)))

for a_n in m1:
    for b_n in m2:
        print(sum([i*j for i, j in zip(a_n, b_n)]), end=" ")
    print("")

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int, input().split())

m1 = [list(map(int, input().split())) for _ in range(n)]
m2 = [list(map(int, input().split())) for _ in range(m)]
m2 = list(map(list, zip(*m2)))

for n, a_n in enumerate(m1):
    for b_n in m2:
        print(sum([i*j for i, j in zip(a_n, b_n)]), end=" ")
    if n < l: print("")

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = 0
for k in range(n):
    for i in range(n):
        for j in range(m):
            num += a[k][j] * b[j][i]
        print(num,end="")
        print(' ',end="")
        num = 0
    print()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = 0
for k in range(n):
    for i in range(n):
        for j in range(m):
            num += a[k][j] * b[j][i]
        print(num,end="")
        print(' ',end="")
        num = 0
    print()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = 0
for k in range(n):
    for i in range(l):
        for j in range(m):
            num += a[k][j] * b[j][i]
        print(num,end="")
        print(' ',end="")
        num = 0
    print()

Submission status: WA: Presentation Error

Solution code:
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = 0
for k in range(n):
    for i in range(l):
        for j in range(m):
            num += a[k][j] * b[j][i]
        print(num,end="")
        print(' ',end="")
        num = 0
    print()