시간초과 오류가 발생해서 다른 사람들의 해설을 찾아 해결했다.
import sys
input = sys.stdin.readline
n = int(input())
# Ex) lst = [2, 4, -10, 4, -9]
lst = list(map(int, input().split()))
# Ex) sort_lst = [-10, -9, 2, 4]
sort_lst = sorted(list(set(lst)))
# Ex) num_dict = {-10:0, -9:1, 2:2, 4:3]
num_dict = {sort_lst[i] : i for i in range(len(sort_lst))}
# Ex) i == 2(lst[0])일 때, num_dict[i] == 2
# Ex) i == 4(lst[1])일 때, num_dict[i] == 3
for i in lst:
sys.stdout.write("{} ". format(str(num_dict[i])))
'백준' 카테고리의 다른 글
[백준] 2164번 파이썬 (카드2) (0) | 2024.02.19 |
---|---|
[백준] 1929번 파이썬 (소수 구하기) (0) | 2024.02.18 |
[백준] 1874번 파이썬 (스택 수열) (0) | 2024.02.18 |
[백준] 1654번 파이썬 (랜선 자르기) (0) | 2024.02.18 |
[백준] 7785번 파이썬 (회사에 있는 사람) (0) | 2024.02.12 |