λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸƒ algorithm/boj

BOJ 14754 - Pizza Boxes

by HandHand 2021. 3. 18.

문제

λ°±μ€€ 온라인 저지 - 14754번

풀이 κ³Όμ •

ν”Όμžλ°•μŠ€λ“€μ΄ μ£Όμ–΄μ§ˆ λ•Œ μ•žκ³Ό μ˜†μ—μ„œ 봀을 λ•Œ μ΅œλŒ€ 높이에 λ³€ν™”κ°€ μ—†λŠ” ν•œμ—μ„œ 없앨 수 μžˆλŠ” ν”Όμžλ°•μŠ€μ˜ 개수λ₯Ό κ΅¬ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.

ν–‰κ³Ό 열을 κΈ°μ€€μœΌλ‘œ νƒμƒ‰ν–ˆμ„ λ•Œ κ°€μž₯ 높은 μœ„μΉ˜μ— μžˆλŠ” ν”Όμžλ“€μ„ 남겨놓고 λ‚˜λ¨Έμ§€λŠ” μ—†μ• λ©΄ λ©λ‹ˆλ‹€.

λ”°λΌμ„œ O(N^2) 의 μ‹œκ°„ λ³΅μž‘λ„λ‘œ μ›ν•˜λŠ” 개수λ₯Ό ꡬ할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ½”λ“œ


import sys


N, M = list(map(int, sys.stdin.readline().split()))
board = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def remove_pizza():
    check = [[0] * M for _ in range(N)]

    for x in range(N):
        max_idx = 0
        for y in range(M):
            if board[x][max_idx] < board[x][y]:
                max_idx = y
        check[x][max_idx] = 1
    for y in range(M):
        max_idx = 0
        for x in range(N):
            if board[max_idx][y] < board[x][y]:
                max_idx = x
        check[max_idx][y] = 1

    return check


def solution():
    answer = 0
    check = remove_pizza()

    for x in range(N):
        for y in range(M):
            if not check[x][y]:
                answer += board[x][y]

    return answer


print(solution())
λ°˜μ‘ν˜•

'πŸƒ algorithm > boj' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

BOJ 18243 - Small World Network  (0) 2021.03.18
BOJ 18238 - ZOAC2  (0) 2021.03.18
BOJ 15723 - n단 논법  (0) 2021.03.18
BOJ 14496 - κ·ΈλŒ€, κ·Έλ¨Έκ°€ λ˜μ–΄  (0) 2021.03.16
BOJ 9311 - Robot in a Maze  (0) 2021.03.14

πŸ’¬ λŒ“κΈ€