結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 👑 obakyanobakyan
提出日時 2022-05-28 21:36:52
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 8,856 KB
最終ジャッジ日時 2023-10-20 23:37:08
合計ジャッジ時間 3,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 65 ms
8,840 KB
testcase_08 AC 68 ms
8,848 KB
testcase_09 AC 74 ms
8,848 KB
testcase_10 AC 73 ms
8,856 KB
testcase_11 AC 69 ms
8,836 KB
testcase_12 AC 70 ms
8,848 KB
testcase_13 AC 67 ms
8,848 KB
testcase_14 AC 64 ms
8,848 KB
testcase_15 AC 63 ms
8,848 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 71 ms
8,848 KB
testcase_21 AC 70 ms
8,824 KB
testcase_22 AC 61 ms
8,852 KB
testcase_23 AC 60 ms
8,848 KB
testcase_24 AC 64 ms
8,856 KB
testcase_25 AC 73 ms
8,700 KB
testcase_26 AC 75 ms
8,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local h, w = io.read("*n", "*n")
local a = {}
for i = 1, h do
  a[i] = {}
  for j = 1, w do
    a[i][j] = io.read("*n")
  end
end
local t1, t2 = {}, {}
for i = 1, h do
  t1[i], t2[i] = {}, {}
  for j = 1, w do
    t1[i][j], t2[i][j] = 0, 0
  end
end

t1[1][1] = a[1][1]
for i = 1, h do
  for j = 1, w do
    if 0 < t1[i][j] then
      if i < h then
        if (i + 1) * j ~= h * w then t2[i + 1][j] = mma(t2[i + 1][j], t1[i][j]) end
        if a[i + 1][j] < t1[i][j] then
          t1[i + 1][j] = mma(t1[i + 1][j], a[i + 1][j] + t1[i][j])
        end
      end
      if j < w then
        if i * (j + 1) ~= h * w then t2[i][j + 1] = mma(t2[i][j + 1], t1[i][j]) end
        if a[i][j + 1] < t1[i][j] then
          t1[i][j + 1] = mma(t1[i][j + 1], a[i][j + 1] + t1[i][j])
        end
      end
    end
    if 0 < t2[i][j] then
      if i < h then
        if a[i + 1][j] < t2[i][j] then
          t2[i + 1][j] = mma(t2[i + 1][j], a[i + 1][j] + t2[i][j])
        end
      end
      if j < w then
        if a[i][j + 1] < t2[i][j] then
          t2[i][j + 1] = mma(t2[i][j + 1], a[i][j + 1] + t2[i][j])
        end
      end
    end
  end
end
print((0 < t1[h][w] or 0 < t2[h][w]) and "Yes" or "No")
0