2021-09-09 게시 됨2026-04-09 업데이트 됨Algorithm / BOJ0회 방문[BOJ] 1967번 : 숨바꼭질문제 보기kotlin 123456789101112131415161718192021222324252627import java.util.*fun main() = with(Scanner(System.`in`)) { val (n, k) = nextInt() to nextInt() val line = Array(100001) { -1 } val queue: Queue<Int> = LinkedList() line[n] = 0 queue.offer(n) while (queue.isNotEmpty()) { val current = queue.poll() val dx = intArrayOf(1, -1, current) for (dir in dx.indices) { val next = current + dx[dir] if (next < 0 || next > 100000) continue if (line[next] != -1) continue line[next] = line[current] + 1 queue.offer(next) } } print(line[k])} #KotlinAlgorithmBOJBFS [BOJ] 1967번 : 숨바꼭질https://june0122.github.io/2021/09/09/boj-1967/AuthorKAMIYUPosted on2021-09-09Updated on2026-04-09Licensed under#KotlinAlgorithmBOJBFS