강의로 돌아가기

### 테스트 케이스 9번

다른 테스트 케이스에 대해서는 모두 통과하였는데, 테스트 케이스 9번에서 런타임 에러가 발생합니다.

도대체 뭐가 문제인걸까요? ㅠㅠ

###### 작성중인 코드―solution.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
A = [[1,0,0],[1,1,1],[0,0,0]] #1
B = [[0,1,0],[0,1,0],[1,1,0]] #1
C = [[1,0,0],[1,0,0],[1,1,0]] #2
D = [[0,0,1],[1,1,1],[0,0,0]] #2
E = [[0,1,0],[1,1,1],[0,0,0]] #3
#F = [[0,0,0],[0,1,0],[1,1,1]] #3
Type = [0,A,B,C,D,E]#,F]
import sys
sys.setrecursionlimit(10**6)
class BLOCK(object):
def __init__(self):
self.coord = []
def append_coord(self,coord):
self.coord.append(coord)
def get_min_xy(self):
x_list = sorted(self.coord, key=lambda x: x[0])
y_list = sorted(self.coord, key=lambda x: x[1])
return x_list[0][0], y_list[0][1]
def get_tpye_num(self):
matrix = [[0]*3 for _ in range(3)]
x,y = self.get_min_xy()
for xy in self.coord:
matrix[xy[0]-x][xy[1]-y] = 1
if matrix in Type:
return Type.index(matrix)
else:
#return False
return 0
def get_black_coord(self,type):
y,x = self.get_min_xy()
return [(0,0)]
# x가 사실은 y이고 y가 사실은 x 임
if type == 1:
return [(y,x+1),(y,x+2)]
elif type == 2:
return [(y+1,x)]
elif type == 3:
return [(y+1,x+1)]
elif type == 4:
return [(y,x),(y,x+1)]
elif type == 5:
return [(y,x),(y,x+2)]

def black_possible(board):
N = len(board)
black_ =[]
for j in range(N):
flag=False
for i in range(N):
if board[i][j] != 0:
black_.append(i-1)
flag=True
break
if flag == False:
black_.append(i)
return black_

def remove_block(board,num):
N = len(board)
for i in range(N):
for j in range(N):
if board[i][j]== num:
board[i][j] = 0
return board

def solution(board):
N = len(board)
# Compute block num
block_num = 0
for i in board:
if block_num < max(i):
block_num = max(i)
# make Block list
Block = [BLOCK() for i in range(block_num)]
# append coord to Block list
for i in range(N):
for j in range(N):
if board[i][j]>0:
Block[ board[i][j]-1 ].append_coord((i,j)) # y,x
AAAAA = list(range(block_num))
while True:
print('*'*10)
flag = False
for i in AAAAA:
type_num = Block[i].get_tpye_num()
#print(i,type_num)
if type_num:
coord = Block[i].get_black_coord(type_num)
# make black coord
tmp = list(range(N))
black = black_possible(board)
black_coord = list(zip(black,tmp))
#print(coord,black_coord)
if set(coord).issubset(set(black_coord)):
flag = True
# could remove
AAAAA.remove(i)
board = remove_block(board,i+1)
#print(board)
break
if flag == False:
break