結果

問題 No.3063 幅優先探索
ユーザー 👑 箱星箱星
提出日時 2020-04-01 21:42:23
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,795 bytes
コンパイル時間 16,364 ms
コンパイル使用メモリ 427,120 KB
実行使用メモリ 64,408 KB
最終ジャッジ日時 2023-09-09 17:28:15
合計ジャッジ時間 20,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
50,124 KB
testcase_01 AC 272 ms
50,208 KB
testcase_02 AC 259 ms
50,220 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 533 ms
64,276 KB
testcase_08 AC 260 ms
52,144 KB
testcase_09 AC 258 ms
50,276 KB
testcase_10 AC 259 ms
50,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:43:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val h = sc.nextInt()
    val w = sc.nextInt()
    val sy = sc.nextInt() - 1
    val sx = sc.nextInt() - 1
    val gy = sc.nextInt() - 1
    val gx = sc.nextInt() - 1
    val map = Array(h) { Array(w) { '.' } }
    for (i in 0 until h) {
        val s = sc.nextLine()
        for (j in 0 until w) {
            map[i][j] = s[j]
        }
    }
    val visited = Array(h) { Array(w) { false } }
    val que: Queue<Triple<Int, Int, Int>> = ArrayDeque()
    que.add(Triple(sy, sx, 0))
    val d = arrayOf(1, 0, -1, 0, 1)
    while (que.count() > 0) {
        val (i, j, step) = que.poll()
        if (i == gy && j == gx) {
            println(step)
            return
        }
        for (k in 0 until 4) {
            val ny = i + d[k]
            val nx = j + d[k + 1]
            if (ny in 0 until h && nx in 0 until w && !visited[ny][nx] && map[ny][nx] == '.') {
                visited[ny][nx] = true
                que.add(Triple(ny, nx, step + 1))
            }
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    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()
    fun ready() = br.ready()
}
0