結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rlangevinrlangevin
提出日時 2023-01-21 01:26:09
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 831 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 849,180 KB
最終ジャッジ日時 2024-06-23 13:02:34
合計ジャッジ時間 8,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 MLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def alp_to_num(cha):
    num = ord(cha) - ord("a")
    return num


H, W = map(int, readline().split())
S = []
for i in range(H):
    L = list(readline().rstrip())
    L = list(map(alp_to_num, L))
    S.append(L)
    
x, y = 0, 0
pre = [[] for i in range(26)]
pre[S[0][0]].append((x, y))
dx, dy = [1, 0], [0, 1]
ans = []
for i in range(H + W - 1):
    dp = [[] for i in range(26)]
    for i, lst in enumerate(pre):
        if lst:
            ans.append(chr(i + ord("a")))
            for nx, ny in lst:
                for k in range(2):
                    x = nx + dx[k]
                    y = ny + dy[k]
                    if x == H or y == W:
                        continue
                    dp[S[x][y]].append((x, y))
            break
    dp, pre = pre, dp
print(*ans, sep="")
0