結果

問題 No.3 ビットすごろく
ユーザー mnrnmnrn
提出日時 2017-06-12 01:07:05
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 341 ms / 5,000 ms
コード長 988 bytes
コンパイル時間 13,687 ms
コンパイル使用メモリ 421,684 KB
実行使用メモリ 55,840 KB
最終ジャッジ日時 2023-09-14 00:46:10
合計ジャッジ時間 26,695 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 302 ms
53,692 KB
testcase_01 AC 312 ms
53,676 KB
testcase_02 AC 314 ms
53,696 KB
testcase_03 AC 319 ms
53,680 KB
testcase_04 AC 311 ms
53,332 KB
testcase_05 AC 341 ms
55,840 KB
testcase_06 AC 326 ms
53,500 KB
testcase_07 AC 310 ms
53,592 KB
testcase_08 AC 305 ms
53,836 KB
testcase_09 AC 314 ms
53,464 KB
testcase_10 AC 324 ms
53,624 KB
testcase_11 AC 315 ms
53,740 KB
testcase_12 AC 313 ms
53,668 KB
testcase_13 AC 315 ms
53,400 KB
testcase_14 AC 323 ms
53,740 KB
testcase_15 AC 323 ms
53,572 KB
testcase_16 AC 324 ms
53,444 KB
testcase_17 AC 315 ms
53,712 KB
testcase_18 AC 304 ms
53,584 KB
testcase_19 AC 319 ms
53,516 KB
testcase_20 AC 304 ms
53,916 KB
testcase_21 AC 308 ms
53,332 KB
testcase_22 AC 328 ms
53,628 KB
testcase_23 AC 330 ms
53,456 KB
testcase_24 AC 328 ms
53,456 KB
testcase_25 AC 322 ms
53,600 KB
testcase_26 AC 310 ms
53,600 KB
testcase_27 AC 320 ms
53,656 KB
testcase_28 AC 319 ms
53,728 KB
testcase_29 AC 320 ms
53,584 KB
testcase_30 AC 316 ms
53,684 KB
testcase_31 AC 315 ms
53,348 KB
testcase_32 AC 325 ms
53,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:8:1: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
inline fun adjlist(i : Int) : Array<Int> {
^
Main.kt:12:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:20:9: warning: variable 'lst' is never used
    val lst = Array(N, { i -> i })
        ^
Main.kt:23:9: warning: variable 'pi' is never used
    var pi = Array(N, { nil })
        ^

ソースコード

diff #

/**
 * Created by n on 2017/06/11.
 */

import java.util.*


inline fun adjlist(i : Int) : Array<Int> {
    return arrayOf((i + 1) - Integer.bitCount(i + 1) - 1, (i + 1) + Integer.bitCount(i + 1) - 1)
}

fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val N = cin.nextInt()

    val inf = Integer.MAX_VALUE / 3
    val nil = Integer.MIN_VALUE / 3

    var q: Queue<Int> = ArrayDeque()
    val lst = Array(N, { i -> i })

    var d = Array(N, { inf })
    var pi = Array(N, { nil })
    var visited = BooleanArray(N)
    val s = 0

    d[s]       = 0
    visited[s] = true

    q.add(0)
    while (q.isNotEmpty()) {
        val u = q.remove()
        val adj = adjlist(u)
        for (v in adj) {
            if (v < 0 || v >= N || visited[v]) {
                continue
            }
            visited[v] = true
            d[v] = d[u] + 1
            q.add(v)
        }
    }
    val ans = if (d[N - 1] == inf) { -1 } else { d[N - 1] + 1}
    println("${ans}")
}
0