結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
👑 |
提出日時 | 2022-10-13 12:51:34 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 1,508 ms / 3,000 ms |
コード長 | 890 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 5,504 KB |
実行使用メモリ | 241,408 KB |
最終ジャッジ日時 | 2024-06-26 11:59:00 |
合計ジャッジ時間 | 16,637 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
local h, w = io.read("*n", "*n", "*l")local t = {}for i = 1, h dolocal s = io.read()t[i] = {}for j = 1, w dot[i][j] = s:sub(j, j)endendlocal ret = {}local last = t[1][1]local pos = {}pos[1] = trueret[1] = lastfor len = 2, h + w - 1 dolocal nxt = "~"for i = 1, h doif pos[i] thenlocal j = len - iif j < w and t[i][j + 1] < nxt thennxt = t[i][j + 1]endif i < h and t[i + 1][j] < nxt thennxt = t[i + 1][j]endendendlocal tmp = {}for i = h, 1, -1 doif pos[i] thenlocal j = len - iif j < w and t[i][j + 1] == nxt thentmp[i] = trueendif i < h and t[i + 1][j] == nxt thentmp[i + 1] = trueendendendpos = {}for k, v in pairs(tmp) dopos[k] = trueendtable.insert(ret, nxt)last = nxtendprint(table.concat(ret))