結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 obakyanobakyan
提出日時 2022-10-13 12:51:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,442 ms / 3,000 ms
コード長 890 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 5,264 KB
実行使用メモリ 264,736 KB
最終ジャッジ日時 2023-09-08 19:03:55
合計ジャッジ時間 16,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 472 ms
105,016 KB
testcase_18 AC 469 ms
104,832 KB
testcase_19 AC 466 ms
105,064 KB
testcase_20 AC 1,370 ms
252,396 KB
testcase_21 AC 1,373 ms
247,056 KB
testcase_22 AC 1,296 ms
237,872 KB
testcase_23 AC 881 ms
205,820 KB
testcase_24 AC 887 ms
205,796 KB
testcase_25 AC 892 ms
206,204 KB
testcase_26 AC 1,442 ms
264,400 KB
testcase_27 AC 1,438 ms
264,736 KB
testcase_28 AC 387 ms
101,800 KB
testcase_29 AC 1,332 ms
257,460 KB
testcase_30 AC 440 ms
99,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local h, w = io.read("*n", "*n", "*l")
local t = {}
for i = 1, h do
  local s = io.read()
  t[i] = {}
  for j = 1, w do
    t[i][j] = s:sub(j, j)
  end
end
local ret = {}
local last = t[1][1]
local pos = {}
pos[1] = true
ret[1] = last
for len = 2, h + w - 1 do
  local nxt = "~"
  for i = 1, h do
    if pos[i] then
      local j = len - i
      if j < w and t[i][j + 1] < nxt then
        nxt = t[i][j + 1]
      end
      if i < h and t[i + 1][j] < nxt then
        nxt = t[i + 1][j]
      end
    end
  end
  local tmp = {}
  for i = h, 1, -1 do
    if pos[i] then
      local j = len - i
      if j < w and t[i][j + 1] == nxt then
        tmp[i] = true
      end
      if i < h and t[i + 1][j] == nxt then
        tmp[i + 1] = true
      end
    end
  end
  pos = {}
  for k, v in pairs(tmp) do
    pos[k] = true
  end
  table.insert(ret, nxt)
  last = nxt
end
print(table.concat(ret))
0