[백준] 14500번 테트로미노

HL·2021년 1월 17일
0

백준

목록 보기
9/104
  • 출처 : 테트로미노

  • 풀이 방법 : 각 인덱스 별로 가능한 모양 모두 가져옴

  • 구현 방법

    • 각 조각 별 함수 만듦
    • 함수 안에 대칭 회전한 모양에 대해 합을 구해서 add
    • max 함수 사용
  • 소감

    • 베스트인지는 모르겠음
    • 다른 문제보다는 쉬웠다

코드

def bar(board, set_sum, i, j):

    if j+3 < len(board[0]):
        set_sum.add(sum(board[i][j:j+4]))

    if i+3 < len(board):
        result = board[i][j]
        result += board[i+1][j]
        result += board[i+2][j]
        result += board[i+3][j]
        set_sum.add(result)

def square(board, set_sum, i, j):

    if i+1 < len(board) and j+1 < len(board[0]):
        result = board[i][j]
        result += board[i+1][j]
        result += board[i][j+1]
        result += board[i+1][j+1]
        set_sum.add(result)

def L(board, set_sum, i, j):

    if i+2 < len(board) and j+1 < len(board[0]):

        result = 0
        result += board[i][j]
        result += board[i+1][j]
        result += board[i+2][j]
        result += board[i+2][j+1]
        set_sum.add(result)

        result = 0
        result += board[i+2][j]
        result += board[i][j+1]
        result += board[i+1][j+1]
        result += board[i+2][j+1]
        set_sum.add(result)

        result = 0
        result += board[i][j]
        result += board[i][j+1]
        result += board[i+1][j]
        result += board[i+2][j]
        set_sum.add(result)

        result = 0
        result += board[i][j]
        result += board[i][j+1]
        result += board[i+1][j+1]
        result += board[i+2][j+1]
        set_sum.add(result)

    if i+1 < len(board) and j+2 < len(board[0]):

        result = 0
        result += board[i][j]
        result += board[i][j+1]
        result += board[i][j+2]
        result += board[i+1][j+2]
        set_sum.add(result)

        result = 0
        result += board[i][j]
        result += board[i+1][j]
        result += board[i][j+1]
        result += board[i][j+2]
        set_sum.add(result)

        result = 0
        result += board[i][j+2]
        result += board[i+1][j]
        result += board[i+1][j+1]
        result += board[i+1][j+2]
        set_sum.add(result)

        result = 0
        result += board[i][j]
        result += board[i+1][j]
        result += board[i+1][j+1]
        result += board[i+1][j+2]
        set_sum.add(result)

def zigzag(board, set_sum, i, j):

    if i+2 < len(board) and j+1 < len(board[0]):

        result = 0
        result += board[i][j]
        result += board[i+1][j]
        result += board[i+1][j+1]
        result += board[i+2][j+1]
        set_sum.add(result)

        result = 0
        result += board[i][j+1]
        result += board[i+1][j+1]
        result += board[i+1][j]
        result += board[i+2][j]
        set_sum.add(result)

    if i+1 < len(board) and j+2 < len(board[0]):

        result = 0
        result += board[i][j+1]
        result += board[i][j+2]
        result += board[i+1][j]
        result += board[i+1][j+1]
        set_sum.add(result)

        result = 0
        result += board[i][j]
        result += board[i][j+1]
        result += board[i+1][j+1]
        result += board[i+1][j+2]
        set_sum.add(result)

def O(board, set_sum, i, j):
    
    if i+1 < len(board) and j+2 < len(board[0]):

        result = 0
        result += board[i][j]
        result += board[i][j+1]
        result += board[i][j+2]
        result += board[i+1][j+1]
        set_sum.add(result)

        result = 0
        result += board[i][j+1]
        result += board[i+1][j]
        result += board[i+1][j+1]
        result += board[i+1][j+2]
        set_sum.add(result)

    if i+2 < len(board) and j+1 < len(board[0]):

        result = 0
        result += board[i+1][j]
        result += board[i][j+1]
        result += board[i+1][j+1]
        result += board[i+2][j+1]
        set_sum.add(result)

        result = 0
        result += board[i+1][j+1]
        result += board[i][j]
        result += board[i+1][j]
        result += board[i+2][j]
        set_sum.add(result)


n, m = map(int, input('').split(' '))

board = []
for i in range(n):
    line = list(map(int, input('').split(' ')))
    board.append(line)

set_sum = set()
for i in range(n):
    for j in range(m):

        bar(board, set_sum, i, j)
        square(board, set_sum, i, j)
        L(board, set_sum, i, j)
        zigzag(board, set_sum, i, j)
        O(board, set_sum, i, j)

print(max(set_sum))
profile
Frontend 개발자입니다.

0개의 댓글