結果

問題 No.1948 足し算するだけのパズルゲーム(1)
コンテスト
ユーザー scaler
提出日時 2024-08-31 09:07:11
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 900 ms / 2,000 ms
コード長 1,089 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,250 ms
コンパイル使用メモリ 274,520 KB
実行使用メモリ 76,816 KB
最終ジャッジ日時 2026-03-09 20:11:56
合計ジャッジ時間 30,257 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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