結果
| 問題 | No.2064 Smallest Sequence on Grid |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-04 11:05:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,704 ms / 3,000 ms |
| コード長 | 590 bytes |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 82,124 KB |
| 実行使用メモリ | 104,960 KB |
| 最終ジャッジ日時 | 2024-11-18 13:01:29 |
| 合計ジャッジ時間 | 16,989 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
H,W = map(int,input().split())
S = [input() for _ in range(H)]
ans = []
s = set()
s.add((0,0))
ans.append(S[0][0])
for _ in range(H + W - 2):
nx = set()
c = "z"
for x,y in s:
if x + 1 < H:
u = S[x + 1][y]
if u < c:
c = u
if y + 1 < W:
u = S[x][y + 1]
if u < c:
c = u
ans.append(c)
for x,y in s:
if x + 1 < H and S[x + 1][y] == c:
nx.add((x + 1,y))
if y + 1 < W and S[x][y + 1] == c:
nx.add((x,y + 1))
s = nx
print("".join(ans))