結果

問題 No.1638 Robot Maze
ユーザー face4face4
提出日時 2021-08-06 22:37:25
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 17,131 ms
コンパイル使用メモリ 450,284 KB
実行使用メモリ 58,932 KB
最終ジャッジ日時 2023-10-17 04:06:47
合計ジャッジ時間 35,650 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 335 ms
58,600 KB
testcase_01 AC 336 ms
58,612 KB
testcase_02 AC 335 ms
58,604 KB
testcase_03 AC 425 ms
58,932 KB
testcase_04 AC 331 ms
58,636 KB
testcase_05 AC 330 ms
58,624 KB
testcase_06 AC 332 ms
58,640 KB
testcase_07 AC 330 ms
58,632 KB
testcase_08 AC 329 ms
58,636 KB
testcase_09 AC 330 ms
58,644 KB
testcase_10 AC 337 ms
58,640 KB
testcase_11 AC 330 ms
58,632 KB
testcase_12 AC 333 ms
58,644 KB
testcase_13 AC 333 ms
58,628 KB
testcase_14 AC 408 ms
58,920 KB
testcase_15 AC 381 ms
58,840 KB
testcase_16 AC 377 ms
58,848 KB
testcase_17 AC 383 ms
58,828 KB
testcase_18 AC 366 ms
58,816 KB
testcase_19 AC 377 ms
58,840 KB
testcase_20 AC 379 ms
58,844 KB
testcase_21 AC 379 ms
58,832 KB
testcase_22 AC 381 ms
58,824 KB
testcase_23 AC 382 ms
58,840 KB
testcase_24 AC 382 ms
58,836 KB
testcase_25 AC 384 ms
58,836 KB
testcase_26 AC 382 ms
58,832 KB
testcase_27 AC 387 ms
58,848 KB
testcase_28 AC 382 ms
58,828 KB
testcase_29 AC 387 ms
58,832 KB
testcase_30 AC 332 ms
58,608 KB
testcase_31 AC 327 ms
58,616 KB
testcase_32 AC 415 ms
58,920 KB
testcase_33 AC 417 ms
58,920 KB
testcase_34 AC 421 ms
58,924 KB
testcase_35 AC 418 ms
58,924 KB
testcase_36 AC 425 ms
58,908 KB
testcase_37 AC 418 ms
58,920 KB
testcase_38 AC 417 ms
58,924 KB
testcase_39 AC 424 ms
58,924 KB
testcase_40 AC 421 ms
58,908 KB
testcase_41 AC 420 ms
58,920 KB
testcase_42 AC 421 ms
58,924 KB
testcase_43 AC 418 ms
58,924 KB
testcase_44 AC 418 ms
58,920 KB
testcase_45 AC 414 ms
58,920 KB
testcase_46 AC 416 ms
58,912 KB
testcase_47 AC 423 ms
58,908 KB
testcase_48 AC 425 ms
58,912 KB
testcase_49 AC 412 ms
58,912 KB
testcase_50 AC 412 ms
58,912 KB
testcase_51 AC 423 ms
58,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*

data class Data(val dist: Long, val pos: Int) : Comparable<Data> {
    override fun compareTo(other: Data): Int {
        return if (dist - other.dist > 0) 1 else -1
    }
}

fun main() {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val line = readLine()!!.split(" ").map { it.toLong() }
    val (si, sj, ti, tj) = readLine()!!.split(" ").map { it.toInt() - 1 }
    val di = listOf(-1, 1, 0, 0)
    val dj = listOf(0, 0, 1, -1)
    val mat = (0 until h).map { readLine()!! }

    val d = List(h) { MutableList(w) { 1L shl 60 } }
    d[si][sj] = 0
    val pq = PriorityQueue<Data>()
    pq.add(Data(d[si][sj], si * w + sj))
    while (pq.isNotEmpty()) {
        val (dist, pos) = pq.poll()
        val i = pos / w
        val j = pos % w
        if (d[i][j] != dist) continue
        for (k in 0 until 4) {
            val ni = i + di[k]
            val nj = j + dj[k]
            if (ni !in 0 until h || nj !in 0 until w || mat[ni][nj] == '#') continue
            val ndist = dist + (if (mat[ni][nj] == '@') line[5] else 0) + line[k]
            if (d[ni][nj] <= ndist) continue
            d[ni][nj] = ndist
            pq.add(Data(ndist, ni * w + nj))
        }
    }
    println(if (d[ti][tj] <= line[4]) "Yes" else "No")
}
0