๐Ÿ—๏ธ Algorithm/๐ŸŸฉ ๋ฐฑ์ค€

๐ŸŸฉ [๋ฐฑ์ค€] [Python] 2630๋ฒˆ_์ƒ‰์ข…์ด ๋งŒ๋“ค๊ธฐ

Dbswnstjd 2022. 11. 9. 06:12

๋ฌธ์ œ

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

 

2630๋ฒˆ: ์ƒ‰์ข…์ด ๋งŒ๋“ค๊ธฐ

์ฒซ์งธ ์ค„์—๋Š” ์ „์ฒด ์ข…์ด์˜ ํ•œ ๋ณ€์˜ ๊ธธ์ด N์ด ์ฃผ์–ด์ ธ ์žˆ๋‹ค. N์€ 2, 4, 8, 16, 32, 64, 128 ์ค‘ ํ•˜๋‚˜์ด๋‹ค. ์ƒ‰์ข…์ด์˜ ๊ฐ ๊ฐ€๋กœ์ค„์˜ ์ •์‚ฌ๊ฐํ˜•์นธ๋“ค์˜ ์ƒ‰์ด ์œ—์ค„๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์ค„๊นŒ์ง€ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

ํ’€์ด

# ๋ฐฑ์ค€ 2630๋ฒˆ ๋ฌธ์ œ - ์ƒ‰์ข…์ด ๋งŒ๋“ค๊ธฐ
n = int(input())
graph = [list(map(int, input().split())) for _ in range(n)]

result = []

def solution(x, y, n):
    half = n // 2
    color = graph[x][y]
    for i in range(x, x+n):
        for j in range(y, y+n):
            if color != graph[i][j]:
                solution(x,y,half)
                solution(x,y+half,half)
                solution(x+half,y,half)
                solution(x+half,y+half,half)
                return
    if color == 0:
        result.append(0)
    else:
        result.append(1)

solution(0,0,n)
print(result.count(0))
print(result.count(1))

๋ถ„ํ• ์ •๋ณต์ด ์ต์ˆ™ํ•˜์ง€ ์•Š์•„์„œ ์‹œ๊ฐ„์ด ์ž๊พธ ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค..