[백준/코틀린] 18870번: 좌표 압축
실버 2
링크
풀이
좌표를 정렬한 뒤, 각 값보다 작은 좌표의 개수를 매핑하여 압축된 좌표를 구합니다.
코드
1
2
3
4
5
6
7
8
fun main() {
val n = readln().toInt()
val x = readln().split(" ").map { it.toInt() }
val indexMap = x.distinct().sorted().withIndex().associate { it.value to it.index }
println(x.joinToString(" ") { "${indexMap[it]}" })
}
This post is licensed under CC BY 4.0 by the author.