|
| 1 | +""" |
| 2 | +2024.12.14, ๊ณผ์ ๋ฌธ์ , 2hour |
| 3 | +""" |
| 4 | + |
| 5 | +import sys |
| 6 | + |
| 7 | +#0. ์
๋ ฅ ๋ณ์๋ฅผ ํตํด ๊ฐ ์นธ์ ์ ์๊ฐ์ ๊ฐ์ง๋ NxM ํ graph ์ ์ |
| 8 | +N,M = map(int,sys.stdin.readline().split()) |
| 9 | +graph=[[0 for _ in range(M)] for k in range(N)] |
| 10 | +for i in range(N) : |
| 11 | + graph[i] = list( map(int,sys.stdin.readline().split())) |
| 12 | + |
| 13 | +max_num = 0 |
| 14 | +#2. graph ๋ด ํน์ ์นธ(์ ๋์ขํ , (row,col)) ๊ธฐ์ค์์ |
| 15 | +#๊ฐ์ง ์ ์๋ 19๊ฐ ํํ์ ํ
ํธ๋ก๋ฏธ๋
ธ ์์ญ ์ ์ ์๋ค์ ํฉ์ ์ต๋ ๊ฐ ์ฐพ๊ธฐ |
| 16 | +#ํจ์ ๋ด๋ถ์์ ์๋์ขํ(r,c)๋ก ์นธ์ ์์น ํ์
|
| 17 | +def tetries_sum (row,col): |
| 18 | + sub_maxsum = 0 |
| 19 | + #2-1. 19๊ฐ ํ
ํธ๋ก๋ฏธ๋
ธ๋ ํฌ๊ฒ 4๊ฐ์ง ์ง์ฌ๊ฐํ ํํ์ ์์ญ์ผ๋ก ์๋ถ๋ฅ |
| 20 | + for n,m in [[1,4],[2,3],[3,2],[4,1]]: |
| 21 | + sub_sum=0 # ํน์ ์นธ(row,col)์์ ๊ฐ์ง ์ ์๋ ์ ์ํฉ ์ค ์ต๋๊ฐ |
| 22 | + |
| 23 | + #2-2. 19๊ฐ ์ค graph(NxM) ์์์ ๊ฐ์ง ์ ์๋ ํ
ํธ๋ก๋ฏธ๋
ธ๋ง ์ ์ฉ |
| 24 | + if row>=0 and row + n <=N and col>=0 and col+m <=M : |
| 25 | + #(1) ์ง์ฌ๊ฐํ(4๊ฐ์ง) ์์ญ๋ด ๋ชจ๋ ์ ์๊ฐ๋ค์ ํฉ |
| 26 | + for r in range(n): |
| 27 | + for c in range(m): |
| 28 | + |
| 29 | + sub_sum +=graph[row + r][col+ c] |
| 30 | + #(2) 2x3 ๊ณผ 3x2 ํํ ์์ญ ์ค ๋น ์ ธ์ผ ํ๋ 2๊ฐ ์นธ๋ค์ ์ ์๊ฐ์ ํฉ ๊ตฌํ๊ธฐ |
| 31 | + if n==2 and m==3 or n==3 and m==2 : |
| 32 | + del_tmp = list() |
| 33 | + #a. 2x3 ์ง์ฌ๊ฐํ ์์ญ ์ค ๋น ์ ธ์ผ ํ๋ 2๊ฐ ์นธ๋ค์ ์กฐํฉ(์๋์ขํ) : 10๊ฐ |
| 34 | + if n == 2 and m == 3 : |
| 35 | + del_candidates = [[[0,0],[0,1]],[[0,1],[0,2]],[[1,0],[1,1]],[[1,1],[1,2]], |
| 36 | + [[0,0],[1,0]],[[0,2],[1,2]],[[0,0],[1,2]],[[0,2],[1,0]],[[0,0],[0,2]],[[1,0],[1,2]] |
| 37 | + ] |
| 38 | + #b. 3x2 ์ง์ฌ๊ฐํ ์์ญ ์ค ๋น ์ ธ์ผ ํ๋ 2๊ฐ ์นธ๋ค์ ์กฐํฉ(์๋์ขํ) : 10๊ฐ |
| 39 | + elif n==3 and m == 2 : |
| 40 | + del_candidates = [[[0,0],[0,1]], |
| 41 | + [[0,0],[1,0]],[[0,1],[1,1]],[[1,0],[2,0]],[[1,1],[2,1]],[[2,0],[2,1]], |
| 42 | + [[0,0],[2,1]],[[2,0],[0,1]],[[0,0],[2,0]],[[0,1],[2,1]]] |
| 43 | + #(3) ๋นผ์ผํ๋ 2๊ฐ ์นธ๋ค์ ์กฐํฉ๋ค(10์ข
๋ฅ)์ ๋ํด ์ ์๊ฐ์ ํฉ ๊ตฌํ๊ธฐ |
| 44 | + for n1,n2 in del_candidates: |
| 45 | + del_tmp.append(graph[row +n1[0]][col+ n1[1]] +graph[row+n2[0]][col+n2[1]]) |
| 46 | + #(4) 2x3 ๋๋ 3x2 ์์ญ์์ ํฉ์ ์ต๋๊ฐ์ ๊ตฌํ๊ธฐ ์ํด 10๊ฐ์ ๋บ ๊ฐ ์ค ์ต์๊ฐ์ผ๋ก ๋นผ๊ธฐ |
| 47 | + sub_sum -= min(del_tmp) |
| 48 | + |
| 49 | + sub_maxsum = max(sub_maxsum , sub_sum) # ์ต๋๊ฐ ์
๋ฐ์ดํธ |
| 50 | + |
| 51 | + |
| 52 | + else : #ํ
ํธ๋ก๋ฏธ๋
ธ๊ฐ graph ๋ฒ์๋ฅผ ๋ฒ์ด๋จ -> skip |
| 53 | + continue |
| 54 | + return sub_maxsum # ์ ๋์ขํ(row,col) ์นธ ๊ธฐ์ค์์ ๊ฐ์ง ์ ์๋ ํฉ์ ์ต๋ |
| 55 | + |
| 56 | +max_sum = 0 #์ ์ฒด graph ๋ด ํฉ์ ์ต๋๊ฐ |
| 57 | +# 1. graph ๋ด ๋ชจ๋ ์นธ์ ์ํ |
| 58 | +for i in range(N) : |
| 59 | + for j in range(M) : |
| 60 | + new_sub_sum=tetries_sum(i,j) # 2. ์ ๋ ์ขํ(i,j) ์นธ ๊ธฐ์ค์์ ๊ฐ์ง ์ ์๋ ํฉ์ ์ต๋ ๊ฐ ๊ณ์ฐ |
| 61 | + max_sum= max(max_sum,new_sub_sum) #3.์ ์ฒด graph ๋ด ํฉ์ ์ต๋๊ฐ ์
๋ฐ์ดํธ |
| 62 | +print(max_sum) |
0 commit comments