https://www.acmicpc.net/problem/2740
브론즈 못푸는거 넘 웃겨 아니 안웃겨
0. 입력 받기
n, m = map(int,input().rsplit())
a = []
for _ in range(n):
row = list(map(int,input().rsplit()))
a.append(row)
m, k = map(int,input().rsplit())
b = []
for _ in range(m):
row = list(map(int,input().rsplit()))
b.append(row)
1. 결과를 저장해줄 리스트 만들기
result = [[0 for _ in range(k)] for _ in range(n)]
N x M
행렬과 M x K
행렬을 곱하면 N x K
행렬이 만들어진다.
2. 행렬 곱 처리
for i in range(n):
for j in range(k):
for t in range(m):
result[i][j] += a[i][t] * b[t][j]
[2x3][3x2] 행렬의 곱
import sys
input = sys.stdin.readline
n, m = map(int,input().rsplit())
a = []
for _ in range(n):
row = list(map(int,input().rsplit()))
a.append(row)
m, k = map(int,input().rsplit())
b = []
for _ in range(m):
row = list(map(int,input().rsplit()))
b.append(row)
result = [[0 for _ in range(k)] for _ in range(n)]
for i in range(n):
for j in range(k):
for t in range(m):
result[i][j] += a[i][t] * b[t][j]
for row in result:
for num in row:
print(num, end=" ")
print()