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
37
38
|
def cnt_max_matrix(nums):
row_max=0
row=0
for i in range(len(nums)):
tmp_max=0
for j in nums[i]:
tmp_max+=j.count('9')
if row_max<tmp_max:
row_max=tmp_max
row=i
return row_max
def cnt_matrix(nums):
cnt_max=0
for i in nums:
for j in i:
cnt_max+=j.count('9')
return cnt_max
def transpose(matrix):
rows = len(matrix)
columns = len(matrix[0])
matrix_T = []
for j in range(columns):
row = []
for i in range(rows):
row.append(matrix[i][j])
matrix_T.append(row)
return matrix_T
n,m=map(int,input().split())
nums=[]
for i in range(n):
nums.append(list(map(str,input().split())))
row_max=cnt_max_matrix(nums)
col_max=cnt_max_matrix(transpose(nums))
print(cnt_matrix(nums)- max(row_max,col_max))
|
cs |
문제는 n by m 행렬에서 특정 조건 카운팅 구현 내용인데
처음에는 Matrix Transpose 를 numpy 라이브러리에서 transpose 함수를 썼었는데
백준은 외부 라이브러리 사용이 안돼서
Transpose 함수 자체 구현
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 462. Minimum Moves to Equal Array Elements II (0) | 2022.06.30 |
---|---|
백준 2756 다트 (0) | 2022.06.17 |
codeforces 509A - Maximum in Table (0) | 2022.06.13 |
백준 23809 골뱅이 찍기 - 돌아간 ㅈ (0) | 2022.06.10 |
백준 24265 알고리즘 수업 - 알고리즘의 수행 시간 4 (0) | 2022.06.09 |
댓글