結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2022-10-01 17:06:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 380 ms / 3,000 ms |
| コード長 | 685 bytes |
| コンパイル時間 | 382 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 90,496 KB |
| 最終ジャッジ日時 | 2024-12-23 23:21:53 |
| 合計ジャッジ時間 | 8,119 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
H, W = map(int, input().split())
S = [input() for _ in range(H)]
T = [S[0][0]]
Q = [(0, 0)]
for _ in range(H + W - 2):
Q2 = []
h0 = -1
c = "z"
for h,w in Q:
if w < W - 1 and h > h0:
if S[h][w + 1] == c:
Q2.append((h,w + 1))
elif S[h][w + 1] < c:
c = S[h][w + 1]
Q2 = [(h,w + 1)]
h0 = h
if h < H - 1 and h + 1 > h0:
if S[h + 1][w] == c:
Q2.append((h + 1,w))
elif S[h + 1][w] < c:
c = S[h + 1][w]
Q2 = [(h + 1,w)]
h0 = h + 1
#print(Q2)
Q = Q2
T.append(c)
print("".join(T))
ntuda