結果

問題 No.3 ビットすごろく
ユーザー da_louisda_louis
提出日時 2020-02-12 01:01:41
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 13,896 ms
コンパイル使用メモリ 443,752 KB
実行使用メモリ 56,664 KB
最終ジャッジ日時 2024-04-09 02:20:47
合計ジャッジ時間 22,901 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
54,452 KB
testcase_01 AC 273 ms
54,200 KB
testcase_02 AC 272 ms
54,328 KB
testcase_03 AC 296 ms
56,468 KB
testcase_04 WA -
testcase_05 AC 301 ms
56,488 KB
testcase_06 AC 297 ms
56,492 KB
testcase_07 AC 293 ms
56,492 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 302 ms
56,500 KB
testcase_13 AC 299 ms
56,424 KB
testcase_14 AC 308 ms
56,500 KB
testcase_15 AC 317 ms
56,500 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 296 ms
56,556 KB
testcase_19 WA -
testcase_20 AC 297 ms
56,536 KB
testcase_21 AC 274 ms
54,228 KB
testcase_22 AC 309 ms
56,492 KB
testcase_23 AC 310 ms
56,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 273 ms
54,432 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 278 ms
54,292 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 move1 = BitSet.valueOf(longArrayOf(value.toLong())).cardinality()
        dp[value + move1] = min(dp[value + move1], dp[value] + 1)
        recUpdate(value + move1)
    }

    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] == inf
        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