結果

問題 No.3 ビットすごろく
ユーザー da_louisda_louis
提出日時 2020-02-12 23:49:00
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 355 ms / 5,000 ms
コード長 1,019 bytes
コンパイル時間 14,038 ms
コンパイル使用メモリ 426,248 KB
実行使用メモリ 55,632 KB
最終ジャッジ日時 2023-09-14 01:37:15
合計ジャッジ時間 26,748 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
52,892 KB
testcase_01 AC 302 ms
53,020 KB
testcase_02 AC 311 ms
53,040 KB
testcase_03 AC 335 ms
53,552 KB
testcase_04 AC 327 ms
53,272 KB
testcase_05 AC 341 ms
53,260 KB
testcase_06 AC 329 ms
53,252 KB
testcase_07 AC 330 ms
53,208 KB
testcase_08 AC 355 ms
53,168 KB
testcase_09 AC 352 ms
55,344 KB
testcase_10 AC 352 ms
55,288 KB
testcase_11 AC 346 ms
55,368 KB
testcase_12 AC 345 ms
53,256 KB
testcase_13 AC 329 ms
53,196 KB
testcase_14 AC 350 ms
55,352 KB
testcase_15 AC 352 ms
55,372 KB
testcase_16 AC 354 ms
55,440 KB
testcase_17 AC 355 ms
55,564 KB
testcase_18 AC 338 ms
53,640 KB
testcase_19 AC 346 ms
55,540 KB
testcase_20 AC 321 ms
53,284 KB
testcase_21 AC 309 ms
52,968 KB
testcase_22 AC 352 ms
55,624 KB
testcase_23 AC 348 ms
55,296 KB
testcase_24 AC 349 ms
55,344 KB
testcase_25 AC 350 ms
55,632 KB
testcase_26 AC 309 ms
52,892 KB
testcase_27 AC 335 ms
53,236 KB
testcase_28 AC 352 ms
55,552 KB
testcase_29 AC 350 ms
55,388 KB
testcase_30 AC 311 ms
52,844 KB
testcase_31 AC 311 ms
52,984 KB
testcase_32 AC 353 ms
55,428 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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)
}
0