結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 👑 rin204rin204
提出日時 2022-09-02 21:26:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,041 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 98,308 KB
最終ジャッジ日時 2023-08-10 03:17:06
合計ジャッジ時間 11,449 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,404 KB
testcase_01 AC 69 ms
71,580 KB
testcase_02 AC 69 ms
71,588 KB
testcase_03 AC 69 ms
71,496 KB
testcase_04 AC 70 ms
71,272 KB
testcase_05 AC 70 ms
71,344 KB
testcase_06 AC 69 ms
71,172 KB
testcase_07 AC 69 ms
71,372 KB
testcase_08 AC 70 ms
71,560 KB
testcase_09 AC 69 ms
71,168 KB
testcase_10 AC 73 ms
71,488 KB
testcase_11 AC 72 ms
71,544 KB
testcase_12 AC 72 ms
71,476 KB
testcase_13 AC 79 ms
76,396 KB
testcase_14 AC 79 ms
76,524 KB
testcase_15 AC 78 ms
76,288 KB
testcase_16 AC 78 ms
76,440 KB
testcase_17 AC 148 ms
85,548 KB
testcase_18 AC 150 ms
85,472 KB
testcase_19 AC 148 ms
85,508 KB
testcase_20 AC 887 ms
94,580 KB
testcase_21 AC 901 ms
94,668 KB
testcase_22 AC 651 ms
91,596 KB
testcase_23 AC 504 ms
90,060 KB
testcase_24 AC 506 ms
89,952 KB
testcase_25 AC 506 ms
90,072 KB
testcase_26 AC 848 ms
92,864 KB
testcase_27 AC 867 ms
93,364 KB
testcase_28 AC 149 ms
85,508 KB
testcase_29 AC 1,041 ms
98,308 KB
testcase_30 AC 156 ms
85,648 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