結果

問題 No.2095 High Rise
ユーザー 👑 obakyanobakyan
提出日時 2023-01-25 16:05:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 20,308 KB
最終ジャッジ日時 2023-09-09 03:11:56
合計ジャッジ時間 4,531 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 46 ms
5,064 KB
testcase_18 AC 31 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 50 ms
5,536 KB
testcase_21 AC 96 ms
6,728 KB
testcase_22 AC 474 ms
20,152 KB
testcase_23 AC 479 ms
20,272 KB
testcase_24 AC 484 ms
20,232 KB
testcase_25 AC 488 ms
20,204 KB
testcase_26 AC 474 ms
20,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local h, w = io.read("*n", "*n", "*l")
local a = {}
for i = 1, h do
  a[i] = {}
  local s = io.read()
  for b in s:gmatch("(%d+)") do
    table.insert(a[i], tonumber(b))
  end
end
if h == 1 then
  print(0)
  os.exit()
end
local dp1, dp2 = {}, {}
for i = 1, w do
  dp1[i] = a[1][i]
end
for i = 1, h - 1 do
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  local minpos = 1
  for j = 2, w do
    if src[j] <= src[minpos] then
      minpos = j
    end
  end
  local minval = src[minpos]
  for j = 1, w do
    if j ~= minpos then
      src[j] = mmi(src[j], minval + a[i][j])
    end
  end
  for j = 1, w do
    dst[j] = src[j] + a[i + 1][j]
  end
end
local tbl = h % 2 == 0 and dp2 or dp1
local ans = tbl[1]
for i = 2, w do
  ans = mmi(ans, tbl[i])
end
print(ans)
0