본문 바로가기
Problem Solving/Implementation

[구현 문제] 백준 14500번: 테트로미노

by ggyongi 2021. 5. 28.
반응형

https://www.acmicpc.net/problem/14500

x_lim, y_lim = map(int, input().split())

t = []
for i in range(x_lim):
    t.append(list(map(int,input().split())))
    
answer = 0
#block 1
for i in range(x_lim):
    for j in range(y_lim-3):
        num = t[i][j]+t[i][j+1]+t[i][j+2]+t[i][j+3]
        if answer < num:
            answer = num
for i in range(x_lim-3):
    for j in range(y_lim):
        num = t[i][j]+t[i+1][j]+t[i+2][j]+t[i+3][j]
        if answer < num:
            answer = num
#block 2
for i in range(x_lim-1):
    for j in range(y_lim-1):
        num = t[i][j]+t[i][j+1]+t[i+1][j]+t[i+1][j+1]
        if answer < num:
            answer = num
# 3*2
for i in range(x_lim-2):
    for j in range(y_lim-1):
        a = t[i][j] + t[i + 1][j] + t[i + 2][j] + max(t[i + 2][j + 1],t[i + 1][j + 1],t[i][j + 1])
        b = t[i][j+1] + t[i+1][j+1] + t[i+2][j+1] + max(t[i][j], t[i+1][j], t[i+2][j])
        c = t[i][j] + t[i + 1][j] + t[i + 1][j+1] + t[i + 2][j + 1]
        d = t[i+1][j] + t[i + 2][j] + t[i + 1][j+1] + t[i][j + 1]
        temp = max(a,b,c,d)
        if answer < temp:
            answer = temp
# 2*3
for i in range(x_lim-1):
    for j in range(y_lim-2):
        a = t[i][j] + t[i][j+1] + t[i][j+2] + max(t[i + 1][j],t[i + 1][j+1],t[i + 1][j+2])
        b = t[i+1][j] + t[i+1][j + 1] + t[i+1][j + 2] + max(t[i][j],t[i][j+1],t[i][j+2])
        c = t[i+1][j]+t[i][j+1]+t[i+1][j+1]+t[i][j+2]
        d = t[i][j]+t[i][j+1]+t[i+1][j+1]+t[i+1][j+2]
        temp = max(a, b, c, d)
        if answer < temp:
            answer = temp
print(answer)

회전과 뒤집기까지 생각해서 모든 경우를 그려보고 해당 경우를 모두 탐색해보는 구현 문제.

 

비전공자 네카라 신입 취업 노하우

시행착오 끝에 얻어낸 취업 노하우가 모두 담긴 전자책!

kmong.com

댓글