233.トロミノ


白駿

1.Python


n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]

tetromino = [
    [(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)], 
    [(1,0), (1,1), (1,2), (0,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)],
    [(2,0), (2,1), (1,1), (0,1)],
    [(0,0), (0,1), (1,0), (2,0)], 
    [(0,0), (0,1), (1,1), (2,1)],
    [(0,0), (0,1), (0,2), (1,1)], 
    [(1,0), (1,1), (1,2), (0,1)], 
    [(0,0), (1,0), (2,0), (1,1)], 
    [(1,0), (0,1), (1,1), (2,1)],
    [(1,0), (2,0), (0,1), (1,1)],
    [(0,0), (1,0), (1,1), (2,1)],
    [(1,0), (0,1), (1,1), (0,2)],
    [(0,0), (0,1), (1,1), (1,2)]
]

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)