結果

問題 No.971 いたずらっ子
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-25 17:31:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 946 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 144,096 KB
最終ジャッジ日時 2023-10-23 16:13:30
合計ジャッジ時間 9,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]


H, W = map(int, input().split())
G = [input().rstrip() for _ in range(H)]
dist = [[inf] * W for _ in range(H)]
dist[0][0] = 0
que = [(0, 0, 0)]
while que:
    ds, x, y = heapq.heappop(que)
    if dist[x][y] < ds:
        continue
    d = ds + 1
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        dk = ds + 1 + nx + ny
        if 0 <= nx < H and 0 <= ny < W:
            if G[nx][ny] == "." and dist[nx][ny] > d:
                dist[nx][ny] = d
                heapq.heappush(que, (d, nx, ny))
            elif G[nx][ny] == "k" and dist[nx][ny] > dk:
                dist[nx][ny] = dk
                heapq.heappush(que, (dk, nx, ny))

# if True:
#     import numpy as np
#     print(np.array(dist)[:10, :10])
print(dist[H-1][W-1])
0