BOJ - 17829 - 222-풀링

Updated:

def recursive(arr, N, x1, y1, x2, y2):
    if N == 2:
        ret = []
        for i in range(x1, x2):
            for j in range(y1, y2):
                ret.append(arr[i][j])
        ret.sort()
        return ret[-2]

    temp = []
    a = N // 2

    temp.append(recursive(arr, a, x1, y1, x1 + a, y1 + a))
    temp.append(recursive(arr, a, x1 + a, y1, x1 + N, y1 + a))
    temp.append(recursive(arr, a, x1, y1 + a, x1 + a, y1 + N))
    temp.append(recursive(arr, a, x1 + a, y1 + a, x1 + N, y1 + N))
    temp.sort()

    return temp[-2]

def solution():
    N = int(input())
    arr = []
    for _ in range(N):
        arr.append(list(map(int, input().split())))

    print(recursive(arr, N, 0, 0, N, N))

solution()

https://www.acmicpc.net/problem/17829

Categories:

Updated:

Leave a comment