Skip to content

Commit

Permalink
solve(programmers): LV2_68936_쿼드 압축 후 개수 세기_py
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Apr 2, 2024
1 parent 0cdd750 commit f10e9bf
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

def solution(arr):
answer=list(d(0,0,len(arr),arr))
return answer

def d(sx,sy,unit,arr):
if unit==1 : return (0,1) if arr[sx][sy]==1 else (1,0)

tl=d(sx,sy,unit//2,arr)
tr=d(sx,sy+unit//2,unit//2,arr)
bl=d(sx+unit//2,sy,unit//2,arr)
br=d(sx+unit//2,sy+unit//2,unit//2,arr)

res= tuple(sum(elem) for elem in zip(tl,tr,bl,br))
z,o=res
if z==0 : return (0,1)
if o==0 : return (1,0)

return res


0 comments on commit f10e9bf

Please sign in to comment.