기둥과 보
def isPossible(r):
for y, x, w in r:
# 보라면
if w:
if [y, x - 1, 0] not in r and [y + 1, x - 1, 0] not in r and not ([y - 1, x, 1] in r and [y + 1, x, 1] in r):
return True
# 기둥이라면
else:
if x != 0 and [y, x, 1] not in r and [y - 1, x, 1] not in r and [y, x - 1, 0] not in r:
return True
return False
def solution(n, build_frame):
r = []
i = 1
for y, x, w, t in build_frame:
i += 1
s = [y, x, w]
# 설치
if t:
r.append(s)
if isPossible(r):
r.remove(s)
# 삭제이면
elif t == 0 and s in r:
r.remove(s)
if isPossible(r):
r.append(s)
r = sorted(r, key=lambda x: (x[0], x[1], x[2]))
return rLast updated