-
Notifications
You must be signed in to change notification settings - Fork 1
/
2740.py
36 lines (26 loc) · 921 Bytes
/
2740.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sys import stdin
def product_matrix(arr_first, arr_second):
row = len(arr_first)
column = len(arr_second[0])
value = len(arr_second)
matrix = [[0 for j in range(column)] for i in range(row)]
for i in range(row):
for j in range(column):
for k in range(value):
ret = arr_first[i][k] * arr_second[k][j]
matrix[i][j] += ret
return matrix
if __name__ == "__main__":
n, m = [int(x) for x in stdin.readline().split()]
arr_one = []
for i in range(n):
edges = [int(x) for x in stdin.readline().split()]
arr_one.append(edges)
m, k = [int(x) for x in stdin.readline().split()]
arr_two = []
for j in range(m):
edges = [int(x) for x in stdin.readline().split()]
arr_two.append(edges)
result_matrix = product_matrix(arr_one, arr_two)
for mat in result_matrix:
print(*mat)