def solution(points,routes):
point_dict={} # key : 각 포인트 번호 / value : 좌표(r,c)
for i, (r,c) in enumerate(points,start=1):
point_dict[i]=(r,c)
def get_path(src,dst):
(r1,c1)=src
(r2,c2)=dst
path=[] #r부터 시작해서 목적지까지의 경로를 계속 기록
r_step=1 if r2>r1 else -1
while r1 != r2:
path.append((r1,c1))
r1+=r_step
c_step=1 if c2>c1 else -1
while c1 != c2:
path.append((r1,c1))
c1+=c_step
path.append((r2,c2)) # 마지막 도착지까지 기록
print(f"path={path}")
return path
all_robot_paths=[] # 모든 로봇의 전체 이동 경로
for route in routes:
full_path=[] # 현재 로봇의 최종 이동 경로
for i in range(len(route)-1):
start_id=route[i]
end_id=route[i+1]
start_coord=point_dict[start_id]
end_coord=point_dict[end_id]
segment=get_path(start_coord,end_coord)
# 처음 [2,3]할때 마지막으로 찍힌 좌표가 [3,4]할때
# 시작으로 찍힌 좌표가 중복되므로 중복분 제거
if i>0:
segment=segment[1:]
full_path.extend(segment)
all_robot_paths.append(full_path) # 로봇의 전체경로 담음
print(f"all_robot_paths={all_robot_paths}")
max_len=max(len(path) for path in all_robot_paths)
danger_count=0
for t in range(max_len):
pos_count={}
for path in all_robot_paths:
if t<len(path):
pos=path[t]
pos_count[pos]=pos_count.get(pos,0)+1
print(f"pos_count={pos_count}")
for pos,cnt in pos_count.items():
if cnt>=2:
danger_count+=1
print(f"danger_count={danger_count}")
return danger_count