結果

問題 No.3 ビットすごろく
ユーザー Pump0129Pump0129
提出日時 2018-03-30 07:15:39
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 360 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 14,201 ms
コンパイル使用メモリ 419,292 KB
実行使用メモリ 56,316 KB
最終ジャッジ日時 2023-09-14 00:59:44
合計ジャッジ時間 26,498 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
52,452 KB
testcase_01 AC 263 ms
52,444 KB
testcase_02 AC 261 ms
52,568 KB
testcase_03 AC 278 ms
52,620 KB
testcase_04 AC 266 ms
52,404 KB
testcase_05 AC 287 ms
52,556 KB
testcase_06 AC 277 ms
52,600 KB
testcase_07 AC 276 ms
52,488 KB
testcase_08 AC 291 ms
52,512 KB
testcase_09 AC 307 ms
52,708 KB
testcase_10 AC 315 ms
52,588 KB
testcase_11 AC 309 ms
52,708 KB
testcase_12 AC 295 ms
52,620 KB
testcase_13 AC 279 ms
52,496 KB
testcase_14 AC 300 ms
52,500 KB
testcase_15 AC 348 ms
56,296 KB
testcase_16 AC 357 ms
56,248 KB
testcase_17 AC 360 ms
56,280 KB
testcase_18 AC 277 ms
52,504 KB
testcase_19 AC 358 ms
56,092 KB
testcase_20 AC 265 ms
54,276 KB
testcase_21 AC 263 ms
52,384 KB
testcase_22 AC 310 ms
52,680 KB
testcase_23 AC 351 ms
56,260 KB
testcase_24 AC 359 ms
55,576 KB
testcase_25 AC 349 ms
56,316 KB
testcase_26 AC 255 ms
52,412 KB
testcase_27 AC 275 ms
52,444 KB
testcase_28 AC 306 ms
52,752 KB
testcase_29 AC 306 ms
52,740 KB
testcase_30 AC 268 ms
52,536 KB
testcase_31 AC 265 ms
52,416 KB
testcase_32 AC 302 ms
52,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package net.ipipip0129.kotlin.yukicoder

// 幅優先探索
fun main(args: Array<String>) {
    val len = readLine()!!.toInt()
    val queue = mutableListOf(1)
    // ループ回避用
    val isPass = Array(len, {false})
    // カウント用
    val countList = mutableListOf(1)
    isPass[0] = true


    while (queue.size != 0) {
        val np = queue[0]
        queue.removeAt(0)
        val count = countList[0]
        countList.removeAt(0)

        if (np == len) {
            println(count)
            return
        }

        val vp = Integer.toBinaryString(np).filter { s -> s == '1' }.length

        if (np + vp <= len) {
            if (!isPass[np + vp - 1]) {
                queue.add(np + vp)
                countList.add(count + 1)
                isPass[np + vp - 1] = true
            }
        }

        if (0 < np - vp) {
            if (!isPass[np - vp - 1]) {
                queue.add(np - vp)
                countList.add(count + 1)
                isPass[np - vp - 1] = true
            }
        }
    }

    println("-1")
}
0