Skip to content

Commit ae9fdd4

Browse files
committed
[level 2] Title: 행렬의 곱셈, Time: 2.59 ms, Memory: 5.06 MB -BaekjoonHub
1 parent ecc5382 commit ae9fdd4

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [level 2] 행렬의 곱셈 - 12949
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12949?language=cpp)
4+
5+
### 성능 요약
6+
7+
메모리: 5.06 MB, 시간: 2.59 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 연습문제
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 03월 19일 17:39:49
20+
21+
### 문제 설명
22+
23+
<p>2차원 행렬 arr1과 arr2를 입력받아, arr1에 arr2를 곱한 결과를 반환하는 함수, solution을 완성해주세요.</p>
24+
25+
<h5>제한 조건</h5>
26+
27+
<ul>
28+
<li>행렬 arr1, arr2의 행과 열의 길이는 2 이상 100 이하입니다.</li>
29+
<li>행렬 arr1, arr2의 원소는 -10 이상 20 이하인 자연수입니다.</li>
30+
<li>곱할 수 있는 배열만 주어집니다.</li>
31+
</ul>
32+
33+
<h5>입출력 예</h5>
34+
<table class="table">
35+
<thead><tr>
36+
<th>arr1</th>
37+
<th>arr2</th>
38+
<th>return</th>
39+
</tr>
40+
</thead>
41+
<tbody><tr>
42+
<td>[[1, 4], [3, 2], [4, 1]]</td>
43+
<td>[[3, 3], [3, 3]]</td>
44+
<td>[[15, 15], [15, 15], [15, 15]]</td>
45+
</tr>
46+
<tr>
47+
<td>[[2, 3, 2], [4, 2, 4], [3, 1, 4]]</td>
48+
<td>[[5, 4, 3], [2, 4, 1], [3, 1, 1]]</td>
49+
<td>[[22, 22, 11], [36, 28, 18], [29, 20, 14]]</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
54+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <string>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
7+
8+
9+
int row1 = arr1.size();
10+
int col1 = arr1[0].size();
11+
int row2 = arr2.size();
12+
int col2 = arr2[0].size();
13+
14+
vector<vector<int>> answer(row1, vector<int>(col2, 0));
15+
16+
for(int i=0; i<row1; i++){
17+
for(int j=0; j<col2 ; j++){
18+
int tmp = 0;
19+
for(int k=0; k<col1; k++){
20+
tmp += (arr1[i][k]*arr2[k][j]);
21+
}
22+
answer[i][j] = tmp;
23+
}
24+
}
25+
26+
return answer;
27+
}

0 commit comments

Comments
 (0)