ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 14500 |
문제명 | 테트로미노 |
레벨 | 골드 5 |
분류 |
구현 |
시간복잡도 | O(nm) |
인풋사이즈 | n<=500, m<=500 |
사용한 언어 | Python |
제출기록 | 35256KB / 1076ms |
최고기록 | 248ms |
해결날짜 | 2021/11/15 |
"""Solution code for "BOJ 14500. 테트로미노".
- Problem link: https://www.acmicpc.net/problem/14500
- Solution link: http://www.teferi.net/ps/problems/boj/14500
Tags: [Implementation]
"""
TETROMINOES = (
# I
((0, 0), (0, 1), (0, 2), (0, 3)),
((0, 0), (1, 0), (2, 0), (3, 0)),
# O
((0, 0), (0, 1), (1, 0), (1, 1)),
# T
((0, 0), (0, 1), (0, 2), (1, 1)),
((0, 0), (1, 0), (1, 1), (2, 0)),
((0, 1), (1, 0), (1, 1), (1, 2)),
((0, 1), (1, 0), (1, 1), (2, 1)),
# J
((0, 0), (0, 1), (0, 2), (1, 2)),
((0, 0), (0, 1), (1, 0), (2, 0)),
((0, 0), (1, 0), (1, 1), (1, 2)),
((0, 1), (1, 1), (2, 0), (2, 1)),
# L
((0, 0), (0, 1), (0, 2), (1, 0)),
((0, 0), (1, 0), (2, 0), (2, 1)),
((0, 2), (1, 0), (1, 1), (1, 2)),
((0, 0), (0, 1), (1, 1), (2, 1)),
# S
((0, 1), (0, 2), (1, 0), (1, 1)),
((0, 0), (1, 0), (1, 1), (2, 1)),
# Z
((0, 0), (0, 1), (1, 1), (1, 2)),
((0, 1), (1, 0), (1, 1), (2, 0)),
)
def main():
N, M = [int(x) for x in input().split()]
grid = [[int(x) for x in input().split()] for _ in range(N)]
answer = 0
for tet in TETROMINOES:
h = max(r for r, c in tet)
w = max(c for r, c in tet)
for r in range(N - h):
for c in range(M - w):
score = sum(grid[r + dr][c + dc] for dr, dc in tet)
answer = max(score, answer)
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 14500. 테트로미노".
- Problem link: https://www.acmicpc.net/problem/14500
- Solution link: http://www.teferi.net/ps/problems/boj/14500
Tags: [Implementation]
"""
TETROMINOES = (
# I
((0, 0), (0, 1), (0, 2), (0, 3)),
((0, 0), (1, 0), (2, 0), (3, 0)),
# O
((0, 0), (0, 1), (1, 0), (1, 1)),
# T
((0, 0), (0, 1), (0, 2), (1, 1)),
((0, 0), (1, 0), (1, 1), (2, 0)),
((0, 1), (1, 0), (1, 1), (1, 2)),
((0, 1), (1, 0), (1, 1), (2, 1)),
# J
((0, 0), (0, 1), (0, 2), (1, 2)),
((0, 0), (0, 1), (1, 0), (2, 0)),
((0, 0), (1, 0), (1, 1), (1, 2)),
((0, 1), (1, 1), (2, 0), (2, 1)),
# L
((0, 0), (0, 1), (0, 2), (1, 0)),
((0, 0), (1, 0), (2, 0), (2, 1)),
((0, 2), (1, 0), (1, 1), (1, 2)),
((0, 0), (0, 1), (1, 1), (2, 1)),
# S
((0, 1), (0, 2), (1, 0), (1, 1)),
((0, 0), (1, 0), (1, 1), (2, 1)),
# Z
((0, 0), (0, 1), (1, 1), (1, 2)),
((0, 1), (1, 0), (1, 1), (2, 0)),
)
def main():
N, M = [int(x) for x in input().split()]
grid = [[int(x) for x in input().split()] for _ in range(N)]
max_num = max(max(row) for row in grid)
possible_max_score = max_num * 4
answer = 0
for tet in TETROMINOES:
h = max(r for r, c in tet)
w = max(c for r, c in tet)
for r in range(N - h):
for c in range(M - w):
score = possible_max_score
for dr, dc in tet:
score += grid[r + dr][c + dc] - max_num
if score <= answer:
break
else:
answer = score
print(answer)
if __name__ == '__main__':
main()