[BOJ] 18870번 좌표 압축(Python)

천호영·2022년 3월 17일
0

알고리즘

목록 보기
3/100
post-thumbnail

문제를 분석해보면, 중복을 제거한 후 정렬된 리스트에서 각 수에 대응되는 인덱스를 출력하는 문제이다. 매번 인덱스를 찾는 과정을 대신해서 dictionary를 통해 인덱스를 저장했다.

import sys
input = sys.stdin.readline

N = int(input())
arr = list(map(int,input().split()))

idx_dict = dict()
for i,num in enumerate(sorted(list(set(arr)))):
  idx_dict[num]=i


new_idx_arr = [idx_dict[x] for x in arr]
print(*new_idx_arr)

profile
성장!

0개의 댓글