結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー tomeruntomerun
提出日時 2022-05-20 21:59:42
言語 Crystal
(1.11.2)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 14,633 ms
コンパイル使用メモリ 291,460 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2023-10-20 12:37:47
合計ジャッジ時間 13,220 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 32 ms
9,576 KB
testcase_08 AC 40 ms
9,580 KB
testcase_09 AC 41 ms
9,580 KB
testcase_10 AC 42 ms
9,580 KB
testcase_11 AC 40 ms
9,596 KB
testcase_12 AC 35 ms
9,580 KB
testcase_13 AC 35 ms
9,580 KB
testcase_14 AC 35 ms
9,580 KB
testcase_15 AC 35 ms
9,580 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 38 ms
9,608 KB
testcase_21 AC 38 ms
9,584 KB
testcase_22 AC 31 ms
9,576 KB
testcase_23 AC 31 ms
9,580 KB
testcase_24 AC 33 ms
9,608 KB
testcase_25 AC 40 ms
9,448 KB
testcase_26 AC 41 ms
9,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = read_line.split.map(&.to_i)
a = Array.new(h) { read_line.split.map(&.to_i64) }
dp0 = Array.new(h) { Array.new(w, -1i64) }
dp1 = Array.new(h) { Array.new(w, -1i64) }
dp0[0][0] = a[0][0]
h.times do |i|
  w.times do |j|
    if j < w - 1
      if dp0[i][j] > a[i][j + 1]
        dp0[i][j + 1] = {dp0[i][j + 1], dp0[i][j] + a[i][j + 1]}.max
      end
      if dp1[i][j] > a[i][j + 1]
        dp1[i][j + 1] = {dp1[i][j + 1], dp1[i][j] + a[i][j + 1]}.max
      end
      dp1[i][j + 1] = {dp1[i][j + 1], dp0[i][j]}.max
    end
    if i < h - 1
      if dp0[i][j] > a[i + 1][j]
        dp0[i + 1][j] = {dp0[i + 1][j], dp0[i][j] + a[i + 1][j]}.max
      end
      if dp1[i][j] > a[i + 1][j]
        dp1[i + 1][j] = {dp1[i + 1][j], dp1[i][j] + a[i + 1][j]}.max
      end
      dp1[i + 1][j] = {dp1[i + 1][j], dp0[i][j]}.max
    end
  end
end
puts [dp0[-1][-1], dp1[-1][-1]].max > a[-1][-1] ? "Yes" : "No"
0