結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ikomaikoma
提出日時 2022-09-02 21:45:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,491 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 252,948 KB
最終ジャッジ日時 2023-08-10 03:42:11
合計ジャッジ時間 16,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,132 KB
testcase_01 AC 73 ms
71,068 KB
testcase_02 AC 74 ms
71,236 KB
testcase_03 AC 71 ms
71,220 KB
testcase_04 AC 71 ms
71,184 KB
testcase_05 AC 73 ms
71,448 KB
testcase_06 AC 73 ms
71,216 KB
testcase_07 AC 73 ms
71,272 KB
testcase_08 AC 77 ms
75,324 KB
testcase_09 AC 76 ms
75,300 KB
testcase_10 AC 76 ms
75,284 KB
testcase_11 AC 77 ms
75,512 KB
testcase_12 AC 78 ms
75,612 KB
testcase_13 AC 83 ms
76,048 KB
testcase_14 AC 85 ms
76,264 KB
testcase_15 AC 85 ms
76,256 KB
testcase_16 AC 84 ms
76,344 KB
testcase_17 AC 377 ms
213,532 KB
testcase_18 AC 364 ms
213,616 KB
testcase_19 AC 365 ms
213,464 KB
testcase_20 AC 1,201 ms
243,848 KB
testcase_21 AC 1,300 ms
247,040 KB
testcase_22 AC 958 ms
236,248 KB
testcase_23 AC 938 ms
240,200 KB
testcase_24 AC 949 ms
240,044 KB
testcase_25 AC 933 ms
240,160 KB
testcase_26 AC 1,491 ms
252,948 KB
testcase_27 AC 1,490 ms
252,856 KB
testcase_28 AC 392 ms
227,484 KB
testcase_29 AC 1,267 ms
221,916 KB
testcase_30 AC 352 ms
204,632 KB
権限があれば一括ダウンロードができます

ソースコード

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