ποΈ Algorithm/π© λ°±μ€
π© [λ°±μ€] [Python] [Class3] 18870λ²_μ’ν μμΆ
Dbswnstjd
2022. 11. 7. 01:41
λ¬Έμ
https://www.acmicpc.net/problem/18870
18870λ²: μ’ν μμΆ
μμ§μ μμ Nκ°μ μ’ν X1, X2, ..., XNμ΄ μλ€. μ΄ μ’νμ μ’ν μμΆμ μ μ©νλ €κ³ νλ€. Xiλ₯Ό μ’ν μμΆν κ²°κ³Ό X'iμ κ°μ Xi > Xjλ₯Ό λ§μ‘±νλ μλ‘ λ€λ₯Έ μ’νμ κ°μμ κ°μμΌ νλ€. X1, X2, ..., XNμ μ’
www.acmicpc.net
νμ΄
# λ°±μ€ 18870λ² λ¬Έμ - μ’ν μμΆ
n = int(input())
x = list(map(int, input().split()))
new_x = list(sorted(set(x)))
dict = {new_x[i]: i for i in range(len(new_x))}
for i in x:
print(dict[i], end=" ")
맨 μ²μ μκ°μ΄κ³Όκ° λ μ μκ°λ³΅μ‘λλ₯Ό μκ°νμλ€.
Nμ΄λΌλ μ«μκ° 100λ§μ΄κΈ° λλ¬Έμ μκ°λ³΅μ‘λλ₯Ό λ¨Όμ μκ°νμ΄μΌ νλλ° νμ§ λͺ»νλ€.
index(i)λ μκ°λ³΅μ‘λκ° O(n)μ΄κ³ λμ λ리λ O(1) μ΄λ―λ‘ λμ λ리λ₯Ό μ¬μ©ν΄μΌ νλ€.