結果

問題 No.1638 Robot Maze
ユーザー 👑 箱星箱星
提出日時 2021-08-06 22:01:41
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 1,885 bytes
コンパイル時間 11,933 ms
コンパイル使用メモリ 445,944 KB
実行使用メモリ 54,428 KB
最終ジャッジ日時 2023-10-17 03:24:33
合計ジャッジ時間 27,557 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
51,852 KB
testcase_01 AC 234 ms
51,844 KB
testcase_02 AC 236 ms
51,852 KB
testcase_03 AC 303 ms
54,400 KB
testcase_04 AC 243 ms
51,880 KB
testcase_05 AC 233 ms
51,880 KB
testcase_06 AC 238 ms
51,880 KB
testcase_07 AC 238 ms
51,876 KB
testcase_08 AC 235 ms
51,876 KB
testcase_09 AC 233 ms
51,864 KB
testcase_10 AC 238 ms
51,884 KB
testcase_11 AC 233 ms
51,880 KB
testcase_12 AC 235 ms
51,876 KB
testcase_13 AC 243 ms
51,884 KB
testcase_14 AC 280 ms
54,088 KB
testcase_15 AC 254 ms
54,048 KB
testcase_16 AC 252 ms
54,036 KB
testcase_17 AC 251 ms
54,008 KB
testcase_18 AC 243 ms
51,876 KB
testcase_19 AC 279 ms
54,012 KB
testcase_20 AC 278 ms
54,016 KB
testcase_21 AC 271 ms
53,936 KB
testcase_22 AC 276 ms
53,928 KB
testcase_23 AC 247 ms
53,932 KB
testcase_24 AC 304 ms
53,924 KB
testcase_25 AC 242 ms
53,932 KB
testcase_26 AC 246 ms
53,948 KB
testcase_27 AC 247 ms
53,952 KB
testcase_28 AC 243 ms
53,952 KB
testcase_29 AC 248 ms
53,944 KB
testcase_30 AC 238 ms
51,852 KB
testcase_31 AC 238 ms
51,844 KB
testcase_32 AC 282 ms
54,096 KB
testcase_33 AC 293 ms
54,096 KB
testcase_34 AC 297 ms
54,420 KB
testcase_35 AC 280 ms
54,112 KB
testcase_36 AC 304 ms
54,428 KB
testcase_37 AC 281 ms
54,104 KB
testcase_38 AC 287 ms
54,080 KB
testcase_39 AC 286 ms
54,104 KB
testcase_40 AC 280 ms
54,100 KB
testcase_41 AC 280 ms
54,100 KB
testcase_42 AC 298 ms
54,100 KB
testcase_43 AC 284 ms
54,100 KB
testcase_44 AC 296 ms
54,104 KB
testcase_45 AC 287 ms
54,084 KB
testcase_46 AC 289 ms
54,104 KB
testcase_47 AC 281 ms
54,092 KB
testcase_48 AC 298 ms
54,368 KB
testcase_49 AC 278 ms
54,100 KB
testcase_50 AC 278 ms
54,100 KB
testcase_51 AC 286 ms
54,372 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(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