結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
![]() |
提出日時 | 2022-09-02 22:00:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,063 ms / 3,000 ms |
コード長 | 488 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 81,992 KB |
実行使用メモリ | 108,328 KB |
最終ジャッジ日時 | 2024-11-16 03:25:43 |
合計ジャッジ時間 | 16,985 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
h, w = map(int, input().split()) s = [input() for _ in range(h)] ans = [s[0][0]] tij = {(0, 0)} m = s[0][0] for _ in range(h+w-2): tij_new = set() m_new = "z" for i, j in tij: if s[i][j] == m and i < h-1: tij_new.add((i+1, j)) m_new = min(m_new, s[i+1][j]) if s[i][j] == m and j < w-1: tij_new.add((i, j+1)) m_new = min(m_new, s[i][j+1]) tij = set(tij_new) m = m_new ans.append(m) print("".join(ans))