結果

問題 No.2064 Smallest Sequence on Grid
ユーザー vwxyzvwxyz
提出日時 2023-01-14 23:57:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,764 ms / 3,000 ms
コード長 466 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 121,260 KB
最終ジャッジ日時 2023-08-27 04:30:26
合計ジャッジ時間 22,250 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,168 KB
testcase_01 AC 76 ms
71,516 KB
testcase_02 AC 75 ms
71,324 KB
testcase_03 AC 74 ms
71,296 KB
testcase_04 AC 74 ms
71,328 KB
testcase_05 AC 74 ms
71,624 KB
testcase_06 AC 75 ms
71,656 KB
testcase_07 AC 76 ms
71,624 KB
testcase_08 AC 76 ms
71,552 KB
testcase_09 AC 74 ms
71,168 KB
testcase_10 AC 76 ms
71,496 KB
testcase_11 AC 76 ms
71,240 KB
testcase_12 AC 78 ms
71,368 KB
testcase_13 AC 85 ms
76,792 KB
testcase_14 AC 87 ms
76,600 KB
testcase_15 AC 87 ms
76,960 KB
testcase_16 AC 87 ms
76,768 KB
testcase_17 AC 164 ms
87,148 KB
testcase_18 AC 156 ms
87,196 KB
testcase_19 AC 156 ms
87,152 KB
testcase_20 AC 1,904 ms
103,720 KB
testcase_21 AC 2,100 ms
108,284 KB
testcase_22 AC 1,377 ms
96,764 KB
testcase_23 AC 1,481 ms
103,500 KB
testcase_24 AC 1,471 ms
103,532 KB
testcase_25 AC 1,472 ms
103,412 KB
testcase_26 AC 2,764 ms
121,260 KB
testcase_27 AC 2,754 ms
120,952 KB
testcase_28 AC 153 ms
87,204 KB
testcase_29 AC 2,302 ms
111,148 KB
testcase_30 AC 179 ms
86,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

H,W=map(int,readline().split())
S=[readline().rstrip() for h in range(H)]
ans_lst=[S[0][0]]
queue=[(0,0)]
for _ in range(H+W-2):
    s="{"
    for h,w in queue:
        if h+1<H:
            s=min(s,S[h+1][w])
        if w+1<W:
            s=min(s,S[h][w+1])
    ans_lst.append(s)
    queue=list({(h+1,w) for h,w in queue if h+1<H and S[h+1][w]==s}|{(h,w+1) for h,w in queue if w+1<W and S[h][w+1]==s})
print("".join(ans_lst))
0