거리두기 규칙
자리에 앉아있는 응시자들의 정보와 대기실 구조를 대기실별로 담은 2차원 문자열 배열 places
가 매개변수로 주어진다. 각 대기실별로 거리두기를 지키고 있으면 1을, 한 명이라도 지키지 않고 있으면 0을 배열에 담아 return 하도록 solution 함수를 완성하라.
places
의 행 길이(대기실 개수) = 5places
의 각 행은 하나의 대기실 구조를 나타냅니다.places
의 열 길이(대기실 세로 길이) = 5places
의 원소는 P
,O
,X
로 이루어진 문자열입니다.places
원소의 길이(대기실 가로 길이) = 5P
는 응시자가 앉아있는 자리를 의미합니다.O
는 빈 테이블을 의미합니다.X
는 파티션을 의미합니다.places
에 담겨 있는 5개 대기실의 순서대로, 거리두기 준수 여부를 차례대로 배열에 담습니다.def solution(places):
answer = []
for place in places:
if solve(place):
answer.append(1)
else:
answer.append(0)
return answer
def solve(place):
for x in range(5):
for y in range(5):
if place[x][y] == 'P' and checkFail(x,y,place):
return False
return True
def checkFail(x,y,place):
if y-1>=0 and place[x][y-1] == 'P':
return True
elif y-2>=0 and place[x][y-2] == 'P':
if place[x][y-1] != 'X':
return True
if y+1<5 and place[x][y+1] == 'P':
return True
elif y+2<5 and place[x][y+2] == 'P':
if place[x][y+1] != 'X':
return True
if x+1<5 and place[x+1][y] == 'P':
return True
elif x+2<5 and place[x+2][y] == 'P':
if place[x+1][y] != 'X':
return True
if x+1<5 and y-1>=0 and place[x+1][y-1] == 'P':
if place[x][y-1] != 'X' or place[x+1][y] != 'X':
return True
if x+1<5 and y+1<5 and place[x+1][y+1] == 'P':
if place[x][y+1] != 'X' or place[x+1][y] != 'X':
return True
return False