結果

問題 No.3 ビットすごろく
ユーザー Pump0129Pump0129
提出日時 2018-03-30 06:51:17
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 861 bytes
コンパイル時間 12,102 ms
コンパイル使用メモリ 436,296 KB
実行使用メモリ 54,508 KB
最終ジャッジ日時 2024-04-30 17:55:46
合計ジャッジ時間 20,071 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 254 ms
54,224 KB
testcase_01 AC 264 ms
54,288 KB
testcase_02 AC 250 ms
54,232 KB
testcase_03 AC 245 ms
54,284 KB
testcase_04 AC 252 ms
54,112 KB
testcase_05 AC 257 ms
54,280 KB
testcase_06 AC 248 ms
54,364 KB
testcase_07 AC 255 ms
54,256 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 301 ms
54,236 KB
testcase_13 AC 278 ms
54,412 KB
testcase_14 AC 277 ms
54,312 KB
testcase_15 AC 263 ms
54,152 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 256 ms
54,240 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 256 ms
54,348 KB
testcase_22 AC 268 ms
54,424 KB
testcase_23 AC 257 ms
54,316 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 254 ms
54,140 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 252 ms
54,132 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3: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 isPass = Array(len, { false })

    var np = 1
    var cnt = 1
    isPass[0] = true
    while (np != len) {
        val vp = Integer.toBinaryString(np).filter { s -> s == '1' }.length
        if (len < np + vp) {
            np -= vp
        } else {
            if (isPass[np + vp - 1]) {
                if (np - vp <= 0) {
                    println("-1")
                    return
                } else {
                    np -= vp
                }
            } else {
                np += vp
            }
        }
        if (isPass[np - 1]) {
            println("-1")
            return
        }
        isPass[np - 1] = true
        cnt += 1
    }
    println(cnt)
}
0