結果

問題 No.971 いたずらっ子
ユーザー hedwig100hedwig100
提出日時 2020-04-15 21:28:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 968 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 92,728 KB
最終ジャッジ日時 2024-04-09 18:59:54
合計ジャッジ時間 7,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque

def main():
    h,w = map(int,input().split())
    grid = [list(input()) for _ in range(h)]

    q = deque()
    q.append((0,0))
    dist = [[INF] * w for _ in range(h)]
    dist[0][0] = 0
    while q:
        i,j = q.popleft()
        for k in range(4):
            y = i + dy[k]
            x = j + dx[k]
            if y < 0 or y >= h:
                continue
            if x < 0 or x >= w:
                continue
            if grid[y][x] == 'k':
                if dist[y][x] > dist[i][j] + 1 + y + x:
                    dist[y][x] = dist[i][j] + 1 + y + x
                    q.append((y,x))
            else:
                if dist[y][x] > dist[i][j] + 1:
                    dist[y][x] = dist[i][j] + 1
                    q.append((y,x))
    
    print(dist[-1][-1]) 
if __name__ == '__main__':
    main()
0