結果

問題 No.971 いたずらっ子
ユーザー ttrttr
提出日時 2020-01-29 20:21:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,548 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 161,868 KB
最終ジャッジ日時 2023-10-14 07:00:59
合計ジャッジ時間 7,094 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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
H,W = map(int, input().split())
L = [input() for _ in range(H)]

inf = 10**15
dist = [[inf]*W for _ in range(H)]
h = []
heapq.heappush(h, (0, 0, 0, 0))
while dist[H-1][W-1] == inf:
    temp = heapq.heappop(h)
    d = temp[0]
    i = temp[1]
    j = temp[2]
    sub_d = temp[3]
    if i > 0:
        if L[i-1][j] == "." and dist[i-1][j] > d+1:
            dist[i-1][j] = d+1
            heapq.heappush(h, (d+1, i-1, j, sub_d+1))
        elif L[i-1][j] == "k" and dist[i-1][j] > d+2+sub_d:
            dist[i-1][j] = d+2+sub_d
            heapq.heappush(h, (d+2+sub_d, i-1, j, sub_d+1))
    if i < H-1:
        if L[i+1][j] == "." and dist[i+1][j] > d+1:
            dist[i+1][j] = d+1
            heapq.heappush(h, (d+1, i+1, j, sub_d+1))
        elif L[i+1][j] == "k" and dist[i+1][j] > d+2+sub_d:
            dist[i+1][j] = d+2+sub_d
            heapq.heappush(h, (d+2+sub_d, i+1, j, sub_d+1))
    if j > 0:
        if L[i][j-1] == "." and dist[i][j-1] > d+1:
            dist[i][j-1] = d+1
            heapq.heappush(h, (d+1, i, j-1, sub_d+1))
        elif L[i][j-1] == "k" and dist[i][j-1] > d+2+sub_d:
            dist[i][j-1] = d+2+sub_d
            heapq.heappush(h, (d+2+sub_d, i, j-1, sub_d+1))
    if j < W-1:
        if L[i][j+1] == "." and dist[i][j+1] > d+1:
            dist[i][j+1] = d+1
            heapq.heappush(h, (d+1, i, j+1, sub_d+1))
        elif L[i][j+1] == "k" and dist[i][j+1] > d+2+sub_d:
            dist[i][j+1] = d+2+sub_d
            heapq.heappush(h, (d+2+sub_d, i, j+1, sub_d+1))

print(dist[H-1][W-1])
0