7. [re] 테트로미노

아현·2021년 10월 4일
0

Algorithm

목록 보기
328/400

백준


1. 시뮬레이션



import sys
input = sys.stdin.readline
n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]
tetromino = [
    [(0, 0), (0, 1), (0, 2), (0, 3)], # 1
    [(0, 0), (1, 0), (2, 0), (3, 0)],
    [(0, 0), (0, 1), (1, 0), (1, 1)], # 2
    [(0, 0), (0, 1), (1, 0), (2, 0)], # 3
    [(0, 0), (0, 1), (1, 1), (2, 1)],
    [(0, 0), (1, 0), (1, 1), (1, 2)],
    [(1, 0), (1, 1), (1, 2), (0, 2)],
    [(2, 0), (2, 1), (1, 1), (0, 1)],
    [(0, 0), (1, 0), (2, 0), (2, 1)],
    [(0, 0), (0, 1), (0, 2), (1, 2)],
    [(0, 0), (0, 1), (0, 2), (1, 0)], # 4
    [(1, 0), (2, 0), (0, 1), (1, 1)],
    [(0, 0), (1, 0), (1, 1), (2, 1)],
    [(0, 0), (0, 1), (1, 1), (1, 2)],
    [(1, 0), (0, 1), (1, 1), (0, 2)],
    [(1, 0), (1, 1), (1, 2), (0, 1)], #5
    [(1, 0), (0, 1), (1, 1), (2, 1)],
    [(0, 0), (1, 0), (2, 0), (1, 1)],
    [(0, 0), (0, 1), (0, 2), (1, 1)],

]

answer = 0


def find(x, y):
    global answer
    for i in range(19):
        result = 0
        for j in range(4):
            nx = x + tetromino[i][j][0]
            ny = y + tetromino[i][j][1]
            if 0 <= nx < n and 0 <= ny < m:
                result += board[nx][ny]

        answer = max(answer, result)


for i in range(n):
    for j in range(m):
        find(i, j)

print(answer)




profile
For the sake of someone who studies computer science

0개의 댓글