재귀 비교
import sys
input = sys.stdin.readline
def polling(n,start_x,start_y):
half = n//2
if n==2:
arr = [matrix[start_x][start_y], matrix[start_x+1][start_y], matrix[start_x][start_y+1], matrix[start_x+1][start_y+1]]
arr.sort()
return arr[-2]
left_top = polling(half,start_x,start_y)
right_top = polling(half,start_x+half,start_y)
left_bottom = polling(half,start_x,start_y+half)
right_bottom = polling(half,start_x+half,start_y+half)
arr = [left_top, right_top, left_bottom, right_bottom]
arr.sort()
return arr[-2]
N = int(input())
matrix = [list(map(int, input().split())) for _ in range(N)]
print(polling(N,0,0))
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 15659 연산자끼워넣기 3 (0) | 2021.08.26 |
---|---|
[백준][Python] 2141 우체국 (0) | 2021.08.26 |
[백준][Python] 2435 기상청 인턴 신현수 (0) | 2021.08.26 |
[백준][Python] 15789 CTP왕국은 한솔왕국을 이길 수 있을까? (0) | 2021.08.25 |
[백준][Python] 13905 세부 (1) | 2021.08.25 |