충돌위험 찾기
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 풀이
- (위치x, 위치y,시간) 을 key값으로 하는 딕셔너리 이용해서 횟수 체크
def solution(points, routes):
answer=0
move_dict={}
for route in routes:
time=0
sx,sy=0,0
for idx, point_num in enumerate(route[:-1]):
sx,sy=points[point_num-1]
ex,ey=points[route[idx+1]-1]
while True:
if sx==ex and sy==ey:
break
if (sx,sy,time) in move_dict:
move_dict[(sx,sy,time)]+=1
else:
move_dict[(sx,sy,time)]=1
time+=1
if ex>sx:
sx+=1
elif ex<sx:
sx-=1
else:
if ey>sy:
sy+=1
elif ey<sy:
sy-=1
# 맨마지막 위치가 안담겼기때문에 담아주기
if (sx,sy,time) in move_dict:
move_dict[(sx,sy,time)]+=1
else:
move_dict[(sx,sy,time)]=1
for val in list(move_dict.values()):
if val>=2:
answer+=1
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스] [구현] 3번 / 아날로그 시계 (0) | 2025.01.23 |
|---|---|
| [프로그래머스][그리디] 숫자 게임 (0) | 2024.12.06 |
| [프로그래머스][BFS] 석유 시추 (0) | 2024.11.27 |
| [프로그래머스][구현] 광물 캐기 (0) | 2024.11.27 |
| [프로그래머스][완전탐색] 16498. 작은 벌점 (0) | 2024.11.21 |