結果

問題 No.1638 Robot Maze
ユーザー 箱星箱星
提出日時 2021-08-06 22:01:41
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 1,885 bytes
コンパイル時間 15,102 ms
コンパイル使用メモリ 451,408 KB
実行使用メモリ 51,404 KB
最終ジャッジ日時 2024-09-17 02:00:58
合計ジャッジ時間 33,937 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val h = nextInt()
    val w = nextInt()
    val u = nextLong()
    val d = nextLong()
    val r = nextLong()
    val l = nextLong()
    val k = nextLong()
    val p = nextLong()
    val xs = nextInt() - 1
    val ys = nextInt() - 1
    val xt = nextInt() - 1
    val yt = nextInt() - 1
    val c = Array(h) { nextLine().toCharArray() }
    var min = Long.MAX_VALUE
    val pq = PriorityQueue<Triple<Int, Int, Long>> { x, y -> x.third.compareTo(y.third) }
    pq.add(Triple(xs, ys, 0))
    val visited = Array(h) { BooleanArray(w) { false } }
    val dx = arrayOf(1, -1, 0, 0)
    val dy = arrayOf(0, 0, 1, -1)
    val mc = arrayOf(d, u, r, l)
    while (pq.isNotEmpty()) {
        val (x, y, cost) = pq.poll()
        if (visited[x][y]) continue
        visited[x][y] = true
        if (x == xt && y == yt) {
            min = minOf(min, cost)
        }
        for (i in 0 until 4) {
            val nx = x + dx[i]
            val ny = y + dy[i]
            if (nx in 0 until h && ny in 0 until w && !visited[nx][ny]) {
                if (c[nx][ny] == '.') {
                    pq.add(Triple(nx, ny, cost + mc[i]))
                } else if (c[nx][ny] == '@') {
                    pq.add(Triple(nx, ny, cost + mc[i] + p))
                }
            }
        }
    }
    println(if (min <= k) "Yes" else "No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0