結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rlangevinrlangevin
提出日時 2023-01-21 01:37:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,887 ms / 3,000 ms
コード長 982 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 183,560 KB
最終ジャッジ日時 2023-09-05 17:44:22
合計ジャッジ時間 24,937 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,500 KB
testcase_01 AC 71 ms
71,420 KB
testcase_02 AC 68 ms
71,504 KB
testcase_03 AC 70 ms
71,160 KB
testcase_04 AC 71 ms
71,368 KB
testcase_05 AC 71 ms
71,436 KB
testcase_06 AC 70 ms
71,312 KB
testcase_07 AC 69 ms
71,560 KB
testcase_08 AC 78 ms
76,216 KB
testcase_09 AC 76 ms
76,036 KB
testcase_10 AC 79 ms
76,372 KB
testcase_11 AC 115 ms
76,712 KB
testcase_12 AC 83 ms
76,424 KB
testcase_13 AC 87 ms
76,952 KB
testcase_14 AC 83 ms
76,888 KB
testcase_15 AC 83 ms
76,840 KB
testcase_16 AC 83 ms
76,896 KB
testcase_17 AC 398 ms
162,728 KB
testcase_18 AC 404 ms
163,220 KB
testcase_19 AC 378 ms
163,244 KB
testcase_20 AC 2,061 ms
175,124 KB
testcase_21 AC 2,253 ms
176,640 KB
testcase_22 AC 1,512 ms
170,024 KB
testcase_23 AC 1,650 ms
173,604 KB
testcase_24 AC 1,673 ms
173,804 KB
testcase_25 AC 1,646 ms
174,204 KB
testcase_26 AC 2,865 ms
183,528 KB
testcase_27 AC 2,887 ms
183,560 KB
testcase_28 AC 384 ms
163,284 KB
testcase_29 AC 2,398 ms
160,608 KB
testcase_30 AC 334 ms
149,228 KB
権限があれば一括ダウンロードができます

ソースコード

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