/ 제출 1 /
def check_if_partitions(place, a, b):
#there is partitions
if abs(a[0] - b[0]) == 2:
if place[max(a[0],b[0])-1][a[1]] == ('X' or 'P'):
return True
elif abs(a[1]-b[1]) == 2:
if place[a[0]][max(a[1],b[1])-1] == ('X' or 'P'):
return True
else: # 1, 1 씩 차이
if place[max(a[0],b[0])][min(a[1],b[1])] == ('X' or 'P') and place[min(a[0], b[0])][max(a[1],b[1])] == ('X' or 'P'):
return True
return False
def solution(places):
answer = []
for place in places:
print(places.index(place)+1)
result = 1
people = []
for i in range(len(place)):
for j in range(len(place)):
if place[i][j] == 'P':
people.append((i,j))
for i in range(len(people)-1):
for person in people[i+1:]:
# calc manhat dist with people[i] and person
man_dist = abs(person[0] - people[i][0]) + abs(person[1] - people[i][1])
# 문제되는 상황
if man_dist <= 2:
# 문제 구제 기회
# check all partitions between them
if not check_if_partitions(place, person, people[i]):
# if there is any partition: result = 0
result = 0
print(person, people[i],'not')
else:
result = 1
print(person, people[i],'yes')
answer.append(result)
return answer
채점 결과
정확성: 51.1
합계: 51.1 / 100.0
44 줄 쓰고.. 스스로 잘 읽히는 코드도 아니면서 13/31 맞는 내가 싫다.. 하..
테스트케이스는 다 통과했지만, 채점테케에서 처참한 성적입니다.
어쩌겠어요. 반복하면 좀 나아지겠죠.
이건 시간 많이 잡아먹었으니 다른 분 코드 찾아보고 정리하렵니다.
/ 다른 분들 코드 /
[프로그래머스] LEVEL2 거리두기 확인하기 (Python)
프로그래머스 알고리즘 풀이
velog.io
잘 정리해두셔서 해당 내용을 보고 공부했습니다.
'CodingTest > Programmers' 카테고리의 다른 글
[ 프로그래머스 ] [1차] 다트게임 (0) | 2022.07.01 |
---|---|
[ 프로그래머스 ] 자물쇠와 열쇠 (0) | 2022.07.01 |
[ 프로그래머스 / 파이썬 ] 프렌즈 4블록 (0) | 2022.06.30 |
[ 프로그래머스 ] 후보키 (0) | 2022.06.29 |
[ 프로그래머스 ] 순위 검색 (0) | 2022.06.29 |