結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 KazunKazun
提出日時 2022-09-02 22:25:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,766 ms / 3,000 ms
コード長 618 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 171,040 KB
最終ジャッジ日時 2024-04-27 22:01:42
合計ジャッジ時間 14,973 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,356 KB
testcase_01 AC 31 ms
52,880 KB
testcase_02 AC 32 ms
52,216 KB
testcase_03 AC 31 ms
52,680 KB
testcase_04 AC 31 ms
52,560 KB
testcase_05 AC 32 ms
53,100 KB
testcase_06 AC 32 ms
52,340 KB
testcase_07 AC 32 ms
52,472 KB
testcase_08 AC 34 ms
57,900 KB
testcase_09 AC 33 ms
58,480 KB
testcase_10 AC 42 ms
60,004 KB
testcase_11 AC 35 ms
58,924 KB
testcase_12 AC 35 ms
58,912 KB
testcase_13 AC 44 ms
63,048 KB
testcase_14 AC 46 ms
64,064 KB
testcase_15 AC 45 ms
62,172 KB
testcase_16 AC 45 ms
63,960 KB
testcase_17 AC 241 ms
156,620 KB
testcase_18 AC 221 ms
155,756 KB
testcase_19 AC 235 ms
156,312 KB
testcase_20 AC 1,221 ms
165,744 KB
testcase_21 AC 1,315 ms
166,708 KB
testcase_22 AC 914 ms
162,308 KB
testcase_23 AC 989 ms
163,096 KB
testcase_24 AC 966 ms
163,232 KB
testcase_25 AC 961 ms
163,420 KB
testcase_26 AC 1,733 ms
171,020 KB
testcase_27 AC 1,766 ms
171,040 KB
testcase_28 AC 240 ms
156,012 KB
testcase_29 AC 1,393 ms
150,112 KB
testcase_30 AC 224 ms
142,728 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