Skip to content

Commit 74e7256

Browse files
committed
[BOJ] #14500.테트로미노 / 골드4 / 60(X)
1 parent 449b815 commit 74e7256

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 테트로미노의 전체 경우의 수를 저장
5+
tets = [
6+
# 1x4 막대
7+
[(0, 1), (0, 2), (0, 3)], [(1, 0), (2, 0), (3, 0)],
8+
# 2x2 정사각형
9+
[(0, 1), (1, 0), (1, 1)],
10+
# ㄹ자 모양
11+
[(1, 0), (1, 1), (2, 1)], [(0, 1), (1, 0), (1, -1)],
12+
# ㄹ자 대칭
13+
[(1, 0), (1, -1), (2, -1)], [(0, 1), (1, 1), (1, 2)],
14+
# ㄴ자 모양 (회전 포함)
15+
[(1, 0), (2, 0), (2, 1)], [(0, 1), (0, 2), (1, 0)],
16+
[(0, 1), (1, 1), (2, 1)], [(0, 1), (0, 2), (-1, 2)],
17+
[(1, 0), (2, 0), (2, -1)], [(0, 1), (0, 2), (1, 2)],
18+
# ㄴ자 대칭 (회전 포함)
19+
[(1, 0), (2, 0), (0, 1)], [(1, 0), (1, 1), (1, 2)],
20+
[(1, 0), (1, 1), (1, -1)], [(1, 0), (1, 1), (2, 0)],
21+
# ㅗ자 모양 (회전 포함)
22+
[(0, -1), (0, 1), (1, 0)], [(0, 1), (-1, 1), (1, 1)],
23+
[(0, -1), (0, 1), (-1, 0)], [(1, 0), (0, 1), (-1, 0)],
24+
]
25+
26+
# 주어진 좌표에서 특정 테트로미노를 배치했을 때의 합 계산
27+
def calc(i, j, tet):
28+
total = arr[i][j] # 시작 좌표의 값
29+
for di, dj in tet:
30+
ni, nj = i + di, j + dj
31+
# 범위를 벗어나면 무효
32+
if 0 <= ni < N and 0 <= nj < M:
33+
total += arr[ni][nj]
34+
else:
35+
return 0
36+
return total
37+
38+
# 모든 위치에서 가능한 테트로미노를 배치해 최대값 계산
39+
def max_tetromino_sum():
40+
max_sum = 0
41+
for i in range(N):
42+
for j in range(M):
43+
for tet in tets:
44+
max_sum = max(max_sum, calc(i, j, tet))
45+
return max_sum
46+
47+
48+
N, M = map(int, input().split())
49+
arr = [list(map(int, input().split())) for _ in range(N)]
50+
51+
print(max_tetromino_sum())

0 commit comments

Comments
 (0)