結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー tomeruntomerun
提出日時 2022-05-20 21:58:58
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 893 bytes
コンパイル時間 12,002 ms
コンパイル使用メモリ 280,088 KB
実行使用メモリ 6,464 KB
最終ジャッジ日時 2023-10-20 12:35:12
合計ジャッジ時間 13,888 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 30 ms
6,352 KB
testcase_08 AC 37 ms
6,324 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 32 ms
6,324 KB
testcase_13 AC 32 ms
6,324 KB
testcase_14 AC 32 ms
6,324 KB
testcase_15 AC 31 ms
6,324 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 35 ms
6,356 KB
testcase_21 AC 34 ms
6,312 KB
testcase_22 AC 29 ms
6,320 KB
testcase_23 AC 29 ms
6,324 KB
testcase_24 AC 31 ms
6,320 KB
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = read_line.split.map(&.to_i)
a = Array.new(h) { read_line.split.map(&.to_i) }
dp0 = Array.new(h) { Array.new(w, -1) }
dp1 = Array.new(h) { Array.new(w, -1) }
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