結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rlangevin
提出日時 2023-01-21 01:26:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 831 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 268,240 KB
最終ジャッジ日時 2024-06-23 13:03:03
合計ジャッジ時間 7,611 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 TLE * 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