結果

問題 No.1638 Robot Maze
ユーザー 👑 箱星箱星
提出日時 2021-08-06 21:53:33
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,885 bytes
コンパイル時間 15,942 ms
コンパイル使用メモリ 449,040 KB
実行使用メモリ 54,412 KB
最終ジャッジ日時 2023-10-17 03:15:30
合計ジャッジ時間 33,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
51,820 KB
testcase_01 AC 298 ms
51,824 KB
testcase_02 AC 294 ms
51,840 KB
testcase_03 AC 361 ms
54,380 KB
testcase_04 AC 296 ms
51,860 KB
testcase_05 AC 295 ms
51,864 KB
testcase_06 AC 295 ms
51,856 KB
testcase_07 AC 292 ms
51,852 KB
testcase_08 AC 291 ms
51,864 KB
testcase_09 AC 292 ms
51,856 KB
testcase_10 AC 294 ms
51,864 KB
testcase_11 AC 293 ms
51,860 KB
testcase_12 AC 293 ms
51,864 KB
testcase_13 AC 295 ms
51,860 KB
testcase_14 AC 348 ms
54,076 KB
testcase_15 AC 316 ms
54,028 KB
testcase_16 AC 321 ms
54,032 KB
testcase_17 AC 310 ms
54,000 KB
testcase_18 AC 293 ms
51,868 KB
testcase_19 AC 317 ms
54,016 KB
testcase_20 AC 312 ms
53,996 KB
testcase_21 AC 298 ms
53,928 KB
testcase_22 AC 298 ms
53,916 KB
testcase_23 AC 297 ms
53,916 KB
testcase_24 AC 298 ms
53,908 KB
testcase_25 AC 298 ms
53,912 KB
testcase_26 AC 299 ms
53,924 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 313 ms
53,928 KB
testcase_30 AC 292 ms
51,832 KB
testcase_31 AC 295 ms
51,840 KB
testcase_32 AC 353 ms
54,076 KB
testcase_33 AC 351 ms
54,080 KB
testcase_34 AC 369 ms
54,408 KB
testcase_35 AC 353 ms
54,100 KB
testcase_36 AC 362 ms
54,408 KB
testcase_37 AC 350 ms
54,092 KB
testcase_38 AC 357 ms
54,072 KB
testcase_39 AC 358 ms
54,068 KB
testcase_40 AC 359 ms
54,076 KB
testcase_41 AC 356 ms
54,084 KB
testcase_42 AC 361 ms
54,072 KB
testcase_43 AC 356 ms
54,084 KB
testcase_44 AC 355 ms
54,088 KB
testcase_45 AC 353 ms
54,076 KB
testcase_46 AC 350 ms
54,084 KB
testcase_47 AC 348 ms
54,072 KB
testcase_48 AC 363 ms
54,396 KB
testcase_49 AC 346 ms
54,084 KB
testcase_50 AC 355 ms
54,068 KB
testcase_51 AC 364 ms
54,412 KB
権限があれば一括ダウンロードができます

ソースコード

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(r, l, d, u)
    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