結果

問題 No.3 ビットすごろく
ユーザー da_louisda_louis
提出日時 2020-02-12 23:43:18
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 13,602 ms
コンパイル使用メモリ 435,384 KB
実行使用メモリ 201,996 KB
最終ジャッジ日時 2024-04-15 00:29:16
合計ジャッジ時間 21,568 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
57,560 KB
testcase_01 AC 312 ms
95,060 KB
testcase_02 AC 309 ms
57,060 KB
testcase_03 AC 802 ms
95,308 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
                                                   ^

ソースコード

diff #

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 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 && distances[left] == -1) queue.add(left to distance + 1)
        if (right in 1..n && distances[right] < distance + 1) queue.add(right to distance + 1)
    }

    val answer = distances[n]

    println(answer)
}
0