結果

問題 No.3 ビットすごろく
ユーザー Pump0129
提出日時 2018-03-30 06:51:17
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 861 bytes
コンパイル時間 13,619 ms
コンパイル使用メモリ 432,556 KB
実行使用メモリ 54,464 KB
最終ジャッジ日時 2024-11-20 15:13:22
合計ジャッジ時間 23,808 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
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