結果

問題 No.367 ナイトの転身
ユーザー scalerscaler
提出日時 2024-09-01 11:29:11
言語 Scala(Beta)
(3.4.0)
結果
TLE  
実行時間 -
コード長 1,391 bytes
コンパイル時間 14,465 ms
コンパイル使用メモリ 270,584 KB
実行使用メモリ 90,620 KB
最終ジャッジ日時 2024-09-01 11:29:45
合計ジャッジ時間 33,457 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,057 ms
78,380 KB
testcase_01 AC 1,035 ms
71,044 KB
testcase_02 AC 1,073 ms
71,144 KB
testcase_03 AC 1,084 ms
71,276 KB
testcase_04 AC 1,111 ms
71,192 KB
testcase_05 AC 1,053 ms
71,208 KB
testcase_06 AC 1,091 ms
71,320 KB
testcase_07 AC 1,064 ms
71,012 KB
testcase_08 AC 1,049 ms
71,148 KB
testcase_09 AC 1,084 ms
71,352 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable.PriorityQueue
import scala.io.StdIn.readLine

def unless(condition: Boolean)(block: => Unit): Unit =
  if !condition then block

@main
def yuki367(): Unit =
  
  val dx: Seq[Int] = Seq(1, 1,-1,-1, 1, 1, 2, 2,-1,-1,-2,-2)
  val dy: Seq[Int] = Seq(1,-1,-1, 1, 2,-2, 1,-1, 2,-2, 1,-1)

  val f: Array[Array[Array[Int]]] = Array.ofDim[Int](512, 512, 2)
  for
    i <- 0 until 512
    j <- 0 until 512
    k <- 0 until 2
  do
    f(i)(j)(k) = -1111111
  
  val Array(h, w) = readLine.split(" ").map(_.toInt)
  val s: Array[String] = Array.ofDim[String](h)
  var ans: Int = 0
  for
    i <- 0 until h
  do
    s(i) = readLine
  
  val pq: PriorityQueue[(Int, Int, Int, Int)] = PriorityQueue()
  for
    i <- 0 until h
    j <- 0 until w
    if s(i)(j) == 'S'
  do
    pq.enqueue((0, i, j, 0))

  while pq.nonEmpty do
    var (c, x, y, t) = pq.dequeue
    unless((x < 0 || h <= x || y < 0 || w <= y) || (f(x)(y)(t) >= c)) {
      f(x)(y)(t) = c
      if s(x)(y) == 'R' then
        t = 1 - t
      if t != 0 then
        for i <- 0 until 4 do
          pq.enqueue((c - 1, x + dx(i), y + dy(i), t)) 
      else
        for i <- 0 until 8 do
          pq.enqueue((c - 1, x + dx(i + 4), y + dy(i + 4), t))
    }
  for
    i <- 0 until h
    j <- 0 until w
    if s(i)(j) == 'G'
  do
    ans = -f(i)(j).max
  if ans > 1000000 then
    println(-1)
  else
    println(ans)
0