結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 rin204rin204
提出日時 2022-09-02 21:26:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 968 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 97,308 KB
最終ジャッジ日時 2024-04-27 20:50:57
合計ジャッジ時間 9,784 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,220 KB
testcase_01 AC 39 ms
52,328 KB
testcase_02 AC 38 ms
52,316 KB
testcase_03 AC 38 ms
52,236 KB
testcase_04 AC 39 ms
54,092 KB
testcase_05 AC 84 ms
53,744 KB
testcase_06 AC 38 ms
53,228 KB
testcase_07 AC 38 ms
52,728 KB
testcase_08 AC 40 ms
53,864 KB
testcase_09 AC 39 ms
53,112 KB
testcase_10 AC 41 ms
53,428 KB
testcase_11 AC 41 ms
54,148 KB
testcase_12 AC 41 ms
54,344 KB
testcase_13 AC 49 ms
62,304 KB
testcase_14 AC 49 ms
61,608 KB
testcase_15 AC 50 ms
63,144 KB
testcase_16 AC 49 ms
62,408 KB
testcase_17 AC 120 ms
84,472 KB
testcase_18 AC 119 ms
85,020 KB
testcase_19 AC 118 ms
84,580 KB
testcase_20 AC 790 ms
92,292 KB
testcase_21 AC 832 ms
93,112 KB
testcase_22 AC 587 ms
90,516 KB
testcase_23 AC 461 ms
88,576 KB
testcase_24 AC 467 ms
88,792 KB
testcase_25 AC 473 ms
88,708 KB
testcase_26 AC 808 ms
92,024 KB
testcase_27 AC 803 ms
92,144 KB
testcase_28 AC 117 ms
84,580 KB
testcase_29 AC 968 ms
97,308 KB
testcase_30 AC 126 ms
84,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
S = [input() for _ in range(h)]
def f(i, j):
    return i * w + j
ans = [S[0][0]]
se = {0}
for _ in range(h + w - 2):
    nex = set()
    mi = "z"
    for p in se:
        i = p // w
        j = p - i * w
        if i != h - 1:
            s = S[i + 1][j]
            if s < mi:
                mi = s
                nex = {f(i + 1, j)}
            elif s == mi:
                nex.add(f(i + 1, j))
        if j != w - 1:
            s = S[i][j + 1]
            if s < mi:
                mi = s
                nex = {f(i, j + 1)}
            elif s == mi:
                nex.add(f(i, j + 1))
        
    ans.append(mi)
    se = nex
print(*ans, sep="")
0