結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 KazunKazun
提出日時 2022-09-02 22:00:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 604 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,640 KB
実行使用メモリ 442,108 KB
最終ジャッジ日時 2024-04-27 21:34:29
合計ジャッジ時間 28,529 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,668 KB
testcase_01 AC 37 ms
52,068 KB
testcase_02 AC 38 ms
52,944 KB
testcase_03 AC 38 ms
53,248 KB
testcase_04 AC 38 ms
53,600 KB
testcase_05 AC 37 ms
52,468 KB
testcase_06 AC 38 ms
52,272 KB
testcase_07 AC 37 ms
52,624 KB
testcase_08 AC 38 ms
53,428 KB
testcase_09 AC 38 ms
52,804 KB
testcase_10 AC 40 ms
53,152 KB
testcase_11 AC 40 ms
54,392 KB
testcase_12 AC 39 ms
53,480 KB
testcase_13 AC 49 ms
62,180 KB
testcase_14 AC 49 ms
64,060 KB
testcase_15 AC 48 ms
61,808 KB
testcase_16 AC 50 ms
62,720 KB
testcase_17 AC 749 ms
432,824 KB
testcase_18 AC 732 ms
433,248 KB
testcase_19 AC 732 ms
432,372 KB
testcase_20 AC 2,829 ms
441,104 KB
testcase_21 TLE -
testcase_22 AC 2,031 ms
438,344 KB
testcase_23 AC 2,266 ms
438,900 KB
testcase_24 AC 2,310 ms
439,108 KB
testcase_25 AC 2,244 ms
439,132 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 726 ms
432,936 KB
testcase_29 TLE -
testcase_30 AC 695 ms
401,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

        c=chr(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(c)
    return "".join(T)

print(solve())
0