結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー scaler
提出日時 2024-08-31 09:07:11
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 1,374 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 9,592 ms
コンパイル使用メモリ 267,660 KB
実行使用メモリ 76,444 KB
最終ジャッジ日時 2024-08-31 09:07:54
合計ジャッジ時間 16,188 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn.readLine

@main def yuki1948(): Unit =
  val hw = readLine.split(" ").map(_.toInt)
  val (h, w) = (hw(0), hw(1))
  val dp: Array[Array[Array[Long]]] = Array.ofDim[Long](2, 500, 500)
  val input: Array[Array[Long]] = Array.ofDim[Long](500, 500)
  for
    i <- 0 until h
  do
    input(i) = readLine().split(" ").map(_.toLong)
  dp(0)(0)(0) = input(0)(0)
  for
    f <- 0 until 2
    y <- 0 until h
    x <- 0 until w
  do
    if y < h - 1 then
      if dp(f)(y)(x) > input(y + 1)(x) && dp(f)(y + 1)(x) < dp(f)(y)(x) + input(y + 1)(x) then
        dp(f)(y + 1)(x) = dp(f)(y)(x) + input(y + 1)(x)
      if f == 0 && dp(1)(y + 1)(x) < dp(0)(y)(x) then
        dp(1)(y + 1)(x) = dp(0)(y)(x)
    if x < w - 1 then
      if dp(f)(y)(x) > input(y)(x + 1) && dp(f)(y)(x + 1) < dp(f)(y)(x) + input(y)(x + 1) then
        dp(f)(y)(x + 1) = dp(f)(y)(x) + input(y)(x + 1)
      if f == 0 && dp(1)(y)(x + 1) < dp(0)(y)(x) then
        dp(1)(y)(x + 1) = dp(0)(y)(x)
  val ans = if (dp(0)(h - 1)(w - 1) + dp(1)(h - 1)(w - 1)) > input(h - 1)(w - 1) then "Yes" else "No"
  println(ans)
0