結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 KazunKazun
提出日時 2022-09-02 22:25:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,060 ms / 3,000 ms
コード長 618 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 172,212 KB
最終ジャッジ日時 2023-08-10 04:41:02
合計ジャッジ時間 19,150 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,496 KB
testcase_01 AC 68 ms
71,432 KB
testcase_02 AC 68 ms
71,288 KB
testcase_03 AC 67 ms
71,244 KB
testcase_04 AC 70 ms
71,312 KB
testcase_05 AC 67 ms
71,168 KB
testcase_06 AC 69 ms
71,284 KB
testcase_07 AC 68 ms
71,396 KB
testcase_08 AC 73 ms
75,424 KB
testcase_09 AC 72 ms
75,456 KB
testcase_10 AC 73 ms
75,328 KB
testcase_11 AC 75 ms
75,464 KB
testcase_12 AC 75 ms
75,500 KB
testcase_13 AC 79 ms
76,176 KB
testcase_14 AC 80 ms
76,240 KB
testcase_15 AC 79 ms
76,224 KB
testcase_16 AC 80 ms
76,296 KB
testcase_17 AC 344 ms
157,360 KB
testcase_18 AC 334 ms
156,748 KB
testcase_19 AC 342 ms
157,184 KB
testcase_20 AC 1,508 ms
166,440 KB
testcase_21 AC 1,636 ms
167,616 KB
testcase_22 AC 1,171 ms
163,480 KB
testcase_23 AC 1,202 ms
164,116 KB
testcase_24 AC 1,183 ms
164,472 KB
testcase_25 AC 1,200 ms
164,312 KB
testcase_26 AC 2,060 ms
172,212 KB
testcase_27 AC 2,040 ms
172,108 KB
testcase_28 AC 324 ms
156,668 KB
testcase_29 AC 1,673 ms
151,544 KB
testcase_30 AC 319 ms
144,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    H,W=map(int,input().split())
    S=[]
    for _ in range(H):
        S.append(list(map(ord,input())))

    T=[chr(S[0][0])]
    Y={(0,0)}

    for _ in range(H+W-2):
        X=list(Y)
        Y=set()

        c=ord("z")+1
        for i,j in X:
            if i+1<H and S[i+1][j]<c:
                c=S[i+1][j]
            if j+1<W and S[i][j+1]<c:
                c=S[i][j+1]
        for i,j in X:
            if i+1<H and S[i+1][j]==c:
                Y.add((i+1,j))
            if j+1<W and S[i][j+1]==c:
                Y.add((i,j+1))
        T.append(chr(c))
    return "".join(T)

print(solve())
0