문제 확인하기
2. 정답 코드 (python3, memory: 38184KB, time: 320ms)
def func(num):
cnt = 0
while num:
if num % 10 == 9:
cnt += 1
num //= 10
return cnt
def main():
global max_val
max_val = 0
global sum_val
sum_val = 0
n, m = map(int, input().split())
arr = [[0] * m for _ in range(n)]
row = [0] * n
col = [0] * m
for i in range(n):
arr[i] = list(map(int, input().split()))
for j in range(m):
row[i] += func(arr[i][j])
col[j] += func(arr[i][j])
sum_val += func(arr[i][j])
for i in range(n):
if row[i] > max_val:
max_val = row[i]
for j in range(m):
if col[j] > max_val:
max_val = col[j]
print(sum_val - max_val)
if __name__ == "__main__":
main()