結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ikomaikoma
提出日時 2022-09-02 21:45:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,362 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 251,820 KB
最終ジャッジ日時 2024-04-27 21:15:01
合計ジャッジ時間 14,531 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,564 KB
testcase_01 AC 38 ms
53,556 KB
testcase_02 AC 39 ms
53,244 KB
testcase_03 AC 39 ms
53,660 KB
testcase_04 AC 39 ms
53,100 KB
testcase_05 AC 37 ms
52,340 KB
testcase_06 AC 37 ms
52,680 KB
testcase_07 AC 38 ms
53,728 KB
testcase_08 AC 40 ms
58,320 KB
testcase_09 AC 41 ms
59,220 KB
testcase_10 AC 43 ms
60,344 KB
testcase_11 AC 42 ms
59,084 KB
testcase_12 AC 44 ms
59,240 KB
testcase_13 AC 49 ms
62,840 KB
testcase_14 AC 50 ms
63,140 KB
testcase_15 AC 49 ms
62,988 KB
testcase_16 AC 50 ms
64,532 KB
testcase_17 AC 314 ms
214,888 KB
testcase_18 AC 309 ms
214,476 KB
testcase_19 AC 307 ms
214,372 KB
testcase_20 AC 1,085 ms
242,500 KB
testcase_21 AC 1,219 ms
245,672 KB
testcase_22 AC 846 ms
235,000 KB
testcase_23 AC 870 ms
239,004 KB
testcase_24 AC 897 ms
238,664 KB
testcase_25 AC 848 ms
238,728 KB
testcase_26 AC 1,362 ms
251,348 KB
testcase_27 AC 1,357 ms
251,820 KB
testcase_28 AC 318 ms
214,548 KB
testcase_29 AC 1,189 ms
220,564 KB
testcase_30 AC 312 ms
205,568 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