結果

問題 No.2064 Smallest Sequence on Grid
コンテスト
ユーザー gr1msl3y
提出日時 2022-09-02 21:38:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 584 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 468 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 91,520 KB
最終ジャッジ日時 2026-05-11 06:44:23
合計ジャッジ時間 7,842 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 5 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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