1074번: Z (acmicpc.net)

##
분할정복 문제
재귀로 풀었는데 재귀가 아닌 풀이도 있다

##
import sys
input = sys.stdin.readline
N,r,c = map(int,input().split())
l = 2**N

add = 0
def find_Z(l, r, c):
    global add
   
    if l == 1:
        return 0

    if (r < l//2) and (c < l//2):
        find_Z(l//2,r,c)
    elif (r < l//2) and (c >= l//2):
        add += (l//2)**2
        find_Z(l//2, r, c - l//2)
    elif (r >= l//2) and (c < l//2):
        add += ((l//2)**2)*2
        find_Z(l//2, r - l//2, c)
    else:
        add += ((l//2)**2)*3
        find_Z(l//2, r - l//2, c - l//2)

find_Z(l,r,c)
print(add)


if문에서 등호를 넣는 부분이 틀려서 결과가 안나왔었는데
결국 혼자 풀지는 못했음

global 변수 잘 안쓰다보니 예전에 풀때는 코드가 더럽게 나왔었다
4등분해서 건너뛰는부분 더해가면서 풀면 된다