結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー ntuda
提出日時 2022-10-01 17:06:39
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 230 ms / 3,000 ms
コード長 685 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 263 ms
コンパイル使用メモリ 85,216 KB
実行使用メモリ 94,648 KB
最終ジャッジ日時 2026-05-29 21:03:38
合計ジャッジ時間 7,370 ms
ジャッジサーバーID
(参考情報)
judge4_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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))
0