結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rlangevinrlangevin
提出日時 2023-01-21 01:36:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 982 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 89,712 KB
最終ジャッジ日時 2023-09-05 17:43:19
合計ジャッジ時間 11,723 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,948 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
8,196 KB
testcase_03 AC 16 ms
7,856 KB
testcase_04 AC 15 ms
7,780 KB
testcase_05 AC 16 ms
7,784 KB
testcase_06 AC 16 ms
7,892 KB
testcase_07 AC 16 ms
7,964 KB
testcase_08 AC 17 ms
8,224 KB
testcase_09 AC 16 ms
8,272 KB
testcase_10 AC 17 ms
8,236 KB
testcase_11 AC 18 ms
8,292 KB
testcase_12 AC 18 ms
8,308 KB
testcase_13 AC 19 ms
8,360 KB
testcase_14 AC 25 ms
8,356 KB
testcase_15 AC 23 ms
8,264 KB
testcase_16 AC 23 ms
8,292 KB
testcase_17 AC 1,335 ms
85,152 KB
testcase_18 AC 1,334 ms
85,028 KB
testcase_19 AC 1,332 ms
85,204 KB
testcase_20 TLE -
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(0)
dx, dy = [1, 0], [0, 1]
ans = []
for i in range(H + W - 1):
    dp = [[] for i in range(26)]
    SS = set()
    for i, lst in enumerate(pre):
        if lst:
            ans.append(chr(i + ord("a")))
            for z in lst:
                nx, ny = divmod(z, W)
                for k in range(2):
                    x = nx + dx[k]
                    y = ny + dy[k]
                    if x == H or y == W:
                        continue
                    if (x, y) in SS:
                        continue
                    SS.add((x, y))
                    dp[S[x][y]].append(x * W + y)
            break
    dp, pre = pre, dp
print(*ans, sep="")
0