목적 : 테트로미노 하나를 놓아 테트로미노가 놓인 칸에 쓰여 있는 수들의 합을 최대로 함
구현 문제이고 사각형의 크기가 크지 않기 때문에 한번 브루트 포스로 풀어보도록 하겠다. 하나의 좌표를 기준으로 가능한 모든 테트로미노를 시도하는 것이다.
[(0, 0), (0, 1), (1, 0), (1, 1)],
[(0, 0), (0, 1), (0, 2), (0, 3)],
[(0, 0), (1, 0), (2, 0), (3, 0)],
[(0, 0), (0, 1), (0, 2), (1, 0)],
[(0, 0), (0, 1), (0, 2), (-1, 2)],
[(0, 0), (1, 0), (1, 1), (1, 2)],
[(0, 0), (0, 1), (0, 2), (1, 2)],
[(0, 0), (1, 0), (2, 0), (2, 1)],
[(0, 0), (0, 1), (1, 1), (2, 1)],
[(0, 0), (0, 1), (1, 0), (2, 0)],
[(0, 0), (1, 0), (2, 0), (2, -1)],
[(0, 0), (1, 0), (1, 1), (2, 1)],
[(0, 0), (0, 1), (1, 0), (-1, 1)],
[(0, 0), (0, 1), (1, 0), (1, -1)],
[(0, 0), (0, 1), (1, 1), (1, 2)],
[(0, 0), (0, 1), (0, 2), (1, 1)],
[(0, 0), (1, 0), (1, 1), (1, -1)],
[(0, 0), (1, 0), (2, 0), (1, -1)],
[(0, 0), (1, 0), (1, 1), (2, 0)]
N, M = map(int, input().split())
descarte = []
for _ in range(N):
position = list(map(int, input().split()))
descarte.append(position)
score = []
tetrominos = [
[(0, 0), (0, 1), (1, 0), (1, 1)],
[(0, 0), (0, 1), (0, 2), (0, 3)],
[(0, 0), (1, 0), (2, 0), (3, 0)],
[(0, 0), (0, 1), (0, 2), (1, 0)],
[(0, 0), (0, 1), (0, 2), (-1, 2)],
[(0, 0), (1, 0), (1, 1), (1, 2)],
[(0, 0), (0, 1), (0, 2), (1, 2)],
[(0, 0), (1, 0), (2, 0), (2, 1)],
[(0, 0), (0, 1), (1, 1), (2, 1)],
[(0, 0), (0, 1), (1, 0), (2, 0)],
[(0, 0), (1, 0), (2, 0), (2, -1)],
[(0, 0), (1, 0), (1, 1), (2, 1)],
[(0, 0), (0, 1), (1, 0), (-1, 1)],
[(0, 0), (0, 1), (1, 0), (1, -1)],
[(0, 0), (0, 1), (1, 1), (1, 2)],
[(0, 0), (0, 1), (0, 2), (1, 1)],
[(0, 0), (1, 0), (1, 1), (1, -1)],
[(0, 0), (1, 0), (2, 0), (1, -1)],
[(0, 0), (1, 0), (1, 1), (2, 0)]
]
for i in range(N):
for j in range(M):
for tetro in tetrominos:
amount = 0
for x, y in tetro:
try:
amount += descarte[i+x][j+y]
except IndexError:
break
score.append(amount)
print(max(score))