結果

問題 No.2064 Smallest Sequence on Grid
ユーザー gr1msl3ygr1msl3y
提出日時 2022-09-02 21:38:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 81,604 KB
実行使用メモリ 102,428 KB
最終ジャッジ日時 2024-04-27 21:07:12
合計ジャッジ時間 8,202 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
61,672 KB
testcase_01 AC 34 ms
53,752 KB
testcase_02 AC 34 ms
54,856 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 34 ms
54,096 KB
testcase_06 AC 38 ms
54,604 KB
testcase_07 AC 39 ms
53,536 KB
testcase_08 AC 37 ms
54,528 KB
testcase_09 AC 39 ms
54,496 KB
testcase_10 AC 38 ms
56,188 KB
testcase_11 AC 38 ms
56,644 KB
testcase_12 AC 37 ms
55,444 KB
testcase_13 AC 49 ms
65,496 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 151 ms
85,720 KB
testcase_18 AC 145 ms
85,776 KB
testcase_19 AC 147 ms
85,700 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
H, W = map(int, input().split())
S = [input() for _ in range(H)]

dp = {S[0][0]: {(0, 0)}}
for i in range(H+W-2):
    ndp = defaultdict(set)
    mins = 'z'*(i+1)
    for s in dp:
        for h, w in dp[s]:
            if h < H-1:
                nt = s+S[h+1][w]
                ndp[nt].add((h+1, w))
                mins = min(mins, nt)
            if w < W-1:
                nt = s+S[h][w+1]
                ndp[nt].add((h, w+1))
                mins = min(mins, nt)
    dp = {mins: {t for t in ndp[mins]}}

for k in dp:
    print(k)
    exit()
0