반응형
https://programmers.co.kr/learn/courses/30/lessons/60061
너무 빡코딩이라 스트레쓰를 받는다.
맨정신엔 못푼다.
def solution(n, build_frame):
board = [[[False for _ in range(2)] for _ in range(n+1)] for _ in range(n+1)]
def col_check(x, y):
if y == 0:
return True
if 0<=x<=n and 0<=y<=n and board[x][y][1]:
return True
if 0<=x-1<=n and 0<=y<=n and board[x-1][y][1]:
return True
if 0<=x<=n and 0<=y-1<=n and board[x][y-1][0]:
return True
return False
def bo_check(x,y):
if 0<=x-1<=n and 0<=y<=n and board[x-1][y][1]:
if 0<=x+1<=n and 0<=y<=n and board[x+1][y][1]:
return True
if (0<=x+1<=n and 0<=y-1<=n and board[x+1][y-1][0]) or (0<=x<=n and 0<=y-1<=n and board[x][y-1][0]):
return True
return False
for x, y, a, b in build_frame:
if b == 0: # delete
if a == 0: # column
board[x][y][0] = False
possible = True
for i in range(n+1):
for j in range(n+1):
if board[i][j][0] and not col_check(i,j):
possible = False
if board[i][j][1] and not bo_check(i,j):
possible = False
if not possible:
board[x][y][0] = True
else : # bo
board[x][y][1] = False
possible = True
for i in range(n+1):
for j in range(n+1):
if board[i][j][0] and not col_check(i,j):
possible = False
if board[i][j][1] and not bo_check(i,j):
possible = False
if not possible:
board[x][y][1] = True
else: # setup
if a == 0: # column
if col_check(x,y):
board[x][y][0] = True
else : # bo
if bo_check(x,y):
board[x][y][1] = True
answer = []
for i in range(n+1):
for j in range(n+1):
for k in range(2):
if board[i][j][k]:
answer.append([i,j,k])
return answer
댓글