結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rlangevinrlangevin
提出日時 2023-01-21 01:26:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 831 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 264,084 KB
最終ジャッジ日時 2023-09-05 17:33:45
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,916 KB
testcase_01 AC 16 ms
7,776 KB
testcase_02 AC 17 ms
7,784 KB
testcase_03 AC 17 ms
7,836 KB
testcase_04 AC 16 ms
7,832 KB
testcase_05 AC 16 ms
7,840 KB
testcase_06 AC 16 ms
7,788 KB
testcase_07 AC 17 ms
7,784 KB
testcase_08 AC 17 ms
7,776 KB
testcase_09 AC 16 ms
7,852 KB
testcase_10 AC 18 ms
8,152 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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