programmers.co.kr/learn/courses/30/lessons/60061
p.329
def possible(answer):
for x,y,stuff in answer:
# 기둥 확인
if stuff == 0:
if y==0 or [x-1,y,1] in answer or [x,y,1] in answer or [x,y-1,0] in answer:
continue
else:
return False
elif stuff == 1:
if [x,y-1,0] in answer or [x+1,y-1,0] in answer or ([x-1,y,1] in answer and [x+1,y,1] in answer):
continue
else:
return False
return True
def solution(n, build_frame):
answer=[]
for build in build_frame:
x,y,stuff,op=build
if op==0: # 삭제
answer.remove([x,y,stuff])
if possible(answer)==False:
answer.append([x,y,stuff])
else:
continue
if op==1: # 생성
answer.append([x,y,stuff])
if possible(answer)==False:
answer.remove([x,y,stuff])
else:
continue
answer.sort(key=lambda x:(x[0], x[1], x[2]))
return answer
댓글