結果

問題 No.971 いたずらっ子
ユーザー hedwig100hedwig100
提出日時 2020-04-15 21:31:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,605 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 315,392 KB
最終ジャッジ日時 2024-04-25 02:13:30
合計ジャッジ時間 13,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,605 ms
315,136 KB
testcase_01 AC 1,553 ms
315,392 KB
testcase_02 AC 1,100 ms
255,616 KB
testcase_03 AC 1,224 ms
301,440 KB
testcase_04 AC 1,176 ms
281,728 KB
testcase_05 AC 1,246 ms
301,056 KB
testcase_06 AC 921 ms
251,648 KB
testcase_07 AC 80 ms
77,696 KB
testcase_08 AC 316 ms
134,656 KB
testcase_09 AC 281 ms
132,864 KB
testcase_10 AC 66 ms
72,576 KB
testcase_11 AC 39 ms
53,760 KB
testcase_12 AC 39 ms
53,888 KB
testcase_13 AC 49 ms
62,336 KB
testcase_14 AC 59 ms
67,456 KB
testcase_15 AC 47 ms
61,568 KB
testcase_16 AC 41 ms
54,144 KB
testcase_17 AC 39 ms
53,504 KB
testcase_18 AC 41 ms
53,632 KB
testcase_19 AC 42 ms
53,760 KB
testcase_20 AC 40 ms
53,376 KB
testcase_21 AC 39 ms
53,888 KB
testcase_22 AC 41 ms
54,144 KB
testcase_23 AC 40 ms
53,760 KB
testcase_24 AC 41 ms
53,888 KB
権限があれば一括ダウンロードができます

ソースコード

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(1,3):
            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