-
Notifications
You must be signed in to change notification settings - Fork 0
/
p60061.py
57 lines (51 loc) · 2.61 KB
/
p60061.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def solution(n, build_frame):
answer = []
for b in build_frame:
#print(b)
if b[3] == 0: #삭제
if b[:3] in answer and b[2] == 0:
# 기둥 삭제할 수 있는지 검사
if [b[0], b[1]+1, 0] in answer and ([b[0]-1, b[1]+1, 1] not in answer and [b[0], b[1]+1, 1] not in answer):
continue
if [b[0], b[1]+1, 1] in answer and ([b[0]+1, b[1], 0] not in answer and ([b[0]+1, b[1]+1, 1] not in answer or ([b[0]-1, b[1]+1, 1] not in answer))):
continue
if [b[0]-1, b[1]+1, 1] in answer and ([b[0]-1, b[1], 0] not in answer and ([b[0]-2, b[1]+1, 1] not in answer or ([b[0], b[1]+1, 1] not in answer))):
continue
index = answer.index(b[:3])
del answer[index]
#print('del col ', b[:2])
elif b[:3] in answer and b[2] == 1:
if canRemove(answer, b[:3]) == False:
continue
index = answer.index(b[:3])
del answer[index]
#print('del bo ', b[:2])
elif b[3] == 1: # 추가
if b[2] == 0: # 기둥
if [b[0], b[1], 1] in answer or [b[0]-1, b[1], 1] in answer:
answer.append(b[:3])
elif [b[0], b[1]-1, 0] in answer:
answer.append(b[:3])
elif b[1] == 0:
answer.append(b[:3])
elif b[2] == 1: # 보
if [b[0], b[1]-1, 0] in answer or [b[0]+1, b[1]-1, 0] in answer:
answer.append(b[:3])
elif [b[0]-1, b[1], 1] in answer and [b[0]+1, b[1], 1] in answer:
answer.append(b[:3])
answer = sorted(answer, key=lambda x: (x[0], x[1], x[2]))
if len(answer) == 0:
answer = [[]]
#print(answer)
return answer
def canRemove(answer, b):
if [b[0], b[1], 0] in answer and ([b[0], b[1]-1, 0] not in answer and [b[0]-1, b[1], 1] not in answer): # 기둥 받치고 잇을 경우
return False
if [b[0]+1, b[1], 0] in answer and ([b[0]+1, b[1]-1, 0] not in answer and [b[0]+1, b[1], 1] not in answer): # 기둥 받치고 잇을 경우
return False
if ([b[0]-1, b[1], 1] in answer and [b[0]-2, b[1], 1] in answer) and ([b[0]-1, b[1]-1, 0] not in answer and [b[0], b[1]-1, 0] not in answer):
return False
if [b[0]+1, b[1], 1] in answer and [b[0]+2, b[1], 1] in answer:
if [b[0]+1, b[1]-1, 0] not in answer and [b[0]+2, b[1]-1, 0] not in answer:
return False
return True