結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-02-12 23:49:00 | 
| 言語 | Kotlin (2.1.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 385 ms / 5,000 ms | 
| コード長 | 1,019 bytes | 
| コンパイル時間 | 14,778 ms | 
| コンパイル使用メモリ | 436,460 KB | 
| 実行使用メモリ | 59,472 KB | 
| 最終ジャッジ日時 | 2024-07-01 09:40:13 | 
| 合計ジャッジ時間 | 26,334 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:8:52: warning: 'appendln(Any?): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
private fun StringBuilder.println(message: Any?) = appendln(message)
                                                   ^
            
            ソースコード
import java.util.*
fun main(args: Array<String>) {
    p11()
}
private inline fun printString(builderAction: StringBuilder.() -> Unit) = print(buildString(builderAction))
private fun StringBuilder.println(message: Any?) = appendln(message)
private fun StringBuilder.print(message: Any?) = append(message)
fun p11() = printString {
    val n = readLine()!!.toInt()
    val distances = IntArray(101010) { -1 }
    val visited = mutableSetOf<Int>()
    val queue = ArrayDeque(listOf(1 to 1))
    fun getMoveDistance(value: Int): Int = Integer.bitCount(value)
    while (queue.isNotEmpty()) {
        val (position, distance) = queue.poll()
        distances[position] = distance
        val move = getMoveDistance(position)
        val left = position - move
        val right = position + move
        if (left in 1..n && visited.add(left)) queue.add(left to distance + 1)
        if (right in 1..n && visited.add(right)) queue.add(right to distance + 1)
    }
    val answer = distances[n]
    println(answer)
}
            
            
            
        