結果

問題 No.2064 Smallest Sequence on Grid
ユーザー gr1msl3ygr1msl3y
提出日時 2022-09-02 21:38:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 176,784 KB
最終ジャッジ日時 2024-11-16 02:45:08
合計ジャッジ時間 21,364 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 10 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

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