Skip to content

Commit 229bb5d

Browse files
authored
Merge pull request #106 from learntosurf/main
๏ฟฝLearntosurf / 12์›” 2์ฃผ์ฐจ / 1๋ฌธ์ œ
2 parents ae72a2a + 74e7256 commit 229bb5d

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)