結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ikoma
提出日時 2022-09-02 21:45:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,319 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 251,484 KB
最終ジャッジ日時 2024-11-16 02:57:51
合計ジャッジ時間 13,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[list(map(lambda x:ord(x),input())) for _ in range(H)]
INF=1<<60
check = [[0]*W for _ in range(H)]

ans = [S[0][0]]
que = [(0,0)]
check[0][0]=1
while que:
    que2 = []
    smin = INF
    for h,w in que:
        if h+1<H and check[h+1][w]==0:
            check[h+1][w]=1
            s = S[h+1][w]
            if s < smin:
                smin = s
            que2.append((s,h+1,w))
        if w+1<W and check[h][w+1]==0:
            check[h][w+1]=1
            s = S[h][w+1]
            if s < smin:
                smin = s
            que2.append((s,h,w+1))
    ans.append(smin)
    que = []
    for s,h,w in que2:
        if s==smin:
            que.append((h,w))

print("".join(map(chr, ans[:-1])))
0