結果

問題 No.3 ビットすごろく
ユーザー da_louisda_louis
提出日時 2020-02-12 01:07:43
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 13,633 ms
コンパイル使用メモリ 452,432 KB
実行使用メモリ 56,620 KB
最終ジャッジ日時 2024-04-09 02:31:31
合計ジャッジ時間 24,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
54,300 KB
testcase_01 AC 277 ms
54,208 KB
testcase_02 AC 277 ms
54,280 KB
testcase_03 AC 302 ms
56,508 KB
testcase_04 AC 302 ms
56,352 KB
testcase_05 AC 303 ms
56,560 KB
testcase_06 AC 302 ms
56,620 KB
testcase_07 AC 298 ms
56,408 KB
testcase_08 AC 300 ms
56,404 KB
testcase_09 AC 303 ms
56,580 KB
testcase_10 AC 306 ms
56,456 KB
testcase_11 AC 305 ms
56,444 KB
testcase_12 AC 302 ms
56,332 KB
testcase_13 AC 301 ms
56,500 KB
testcase_14 AC 303 ms
56,484 KB
testcase_15 AC 304 ms
56,484 KB
testcase_16 AC 306 ms
56,332 KB
testcase_17 AC 308 ms
56,620 KB
testcase_18 AC 298 ms
56,332 KB
testcase_19 AC 307 ms
56,500 KB
testcase_20 AC 297 ms
56,360 KB
testcase_21 AC 277 ms
54,440 KB
testcase_22 AC 304 ms
56,476 KB
testcase_23 AC 306 ms
56,416 KB
testcase_24 AC 307 ms
56,476 KB
testcase_25 AC 307 ms
56,536 KB
testcase_26 AC 277 ms
54,348 KB
testcase_27 AC 298 ms
56,444 KB
testcase_28 AC 304 ms
56,460 KB
testcase_29 AC 305 ms
56,416 KB
testcase_30 AC 277 ms
54,424 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.util.*
import kotlin.math.min

fun main(args: Array<String>) {
    p11()
}

fun printString(builderAction: StringBuilder.() -> Unit) = print(buildString(builderAction))

fun p11() = printString {
    val n = readLine()!!.toInt()

    val inf = Int.MAX_VALUE / 100
    val dp = IntArray(101010) { inf }
    dp[1] = 1

    fun recUpdate(value: Int) {
        if (value !in 1..n) return
        val move = BitSet.valueOf(longArrayOf(value.toLong())).cardinality()
        dp[value + move] = min(dp[value + move], dp[value] + 1)
        recUpdate(value + move)
    }

    for (i in 1..n) {
        val move = BitSet.valueOf(longArrayOf(i.toLong())).cardinality()
        val left = i - move
        val right = i + move
        val needReCalc = dp[left] > dp[i] + 1
        dp[right] = min(dp[right], dp[i] + 1)
        dp[left] = min(dp[left], dp[i] + 1)
        if (needReCalc) recUpdate(left)
    }

    val answer = dp[n].let { if (it == inf) -1 else it }

    println(answer)
}
0