ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

๐Ÿšฉ ๋ถ„ํ• ์ •๋ณต

 

thinking

N์ด 1์ด ๋ ๋•Œ๊นŒ์ง€ ์ชผ๊ฐœ๋ฉด์„œ ์ฒดํ‚นํ•˜์ž

๊ทธ๋Ÿผ ์–ด์ผ€ ์ชผ๊ฐค ๊ฒƒ์ด๋ƒ? → ์‹œ์ž‘์ ์˜ ์ขŒํ‘œ๋ฅผ ๊ตฌํ•ด์„œ ์ข…์ดํฌ๊ธฐ๋งŒํผ range๋ฅผ ์„ค์ •ํ•œ ํ›„, ๋ฒ”์œ„ ์ฒดํ‚นํ•˜์ž.

๋ฐ˜๋ณต๋ฌธ ๋Œ๋ฆฌ๋ฉด์„œ ์ฒดํ‚นํ•˜๋‹ค ์ƒ‰๊น”์ด ์ „๋ถ€ ๊ฐ™์œผ๋ฉด ๊ฑฐ๊ธฐ๋Š” stopํ•˜๊ณ  white or blue ๊ฐœ์ˆ˜์— ์นด์šดํŒ…ํ•ด์„œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ค„์ด์ž

 

์ฝ”๋“œ

def divide(s_x,s_y,N):
    global cnt_w, cnt_b
    if N == 1 and a[s_x][s_y] == 0:
        cnt_w += 1
        return
    if N == 1 and a[s_x][s_y] == 1:
        cnt_b += 1
        return

    flag_w = 0
    flag_b = 0
    for i in range(s_x, s_x+N):
        for j in range(s_y, s_y+N):
            if flag_w == 0 and a[i][j] == 0:
                flag_w = 1
            elif flag_b == 0 and a[i][j] == 1:
                flag_b = 1
    N //= 2
    if flag_w == 1 and flag_b == 0:  # ์ „๋ถ€ ํ•˜์–€์ƒ‰์ธ ๊ฒฝ์šฐ -> ํ•˜์–€์ƒ‰ ์นด์šดํŠธํ•˜๊ณ  ๋
        cnt_w += 1
    if flag_w == 0 and flag_b == 1:  # ์ „๋ถ€ ํŒŒ๋ž‘์ƒ‰์ธ ๊ฒฝ์šฐ -> ํŒŒ๋ž‘์ƒ‰ ์นด์šดํŠธํ•˜๊ณ  ๋
        cnt_b += 1
    if flag_w == 1 and flag_b == 1:  # ๋‘˜๋‹ค ๋‚˜์˜ค๋ฉด ์ชผ๊ฐœ๊ธฐ
        divide(s_x, s_y, N)
        divide(s_x + N, s_y, N)
        divide(s_x, s_y + N, N)
        divide(s_x + N, s_y + N, N)



N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
cnt_w, cnt_b = 0, 0
divide(0, 0, N)
print(cnt_w, cnt_b)

 

 

ํ•œ์ค„ํ›„๊ธฐ

ํ• ๋งŒํ–ˆ๋˜ ๋ฌธ์ œ

๋Œ“๊ธ€