結果

問題 No.971 いたずらっ子
ユーザー 👑 tamatotamato
提出日時 2020-01-17 21:36:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,243 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 181,924 KB
最終ジャッジ日時 2023-08-07 07:50:33
合計ジャッジ時間 12,488 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,231 ms
181,924 KB
testcase_01 AC 1,243 ms
181,384 KB
testcase_02 AC 927 ms
156,008 KB
testcase_03 AC 1,075 ms
181,744 KB
testcase_04 AC 1,026 ms
176,048 KB
testcase_05 AC 1,052 ms
181,920 KB
testcase_06 AC 802 ms
157,816 KB
testcase_07 AC 129 ms
78,452 KB
testcase_08 AC 316 ms
103,584 KB
testcase_09 AC 303 ms
102,056 KB
testcase_10 AC 115 ms
77,588 KB
testcase_11 AC 87 ms
71,680 KB
testcase_12 AC 88 ms
71,704 KB
testcase_13 AC 104 ms
77,384 KB
testcase_14 AC 121 ms
78,564 KB
testcase_15 AC 100 ms
77,132 KB
testcase_16 AC 95 ms
76,656 KB
testcase_17 AC 89 ms
71,756 KB
testcase_18 AC 89 ms
71,532 KB
testcase_19 AC 87 ms
71,812 KB
testcase_20 AC 88 ms
71,704 KB
testcase_21 AC 90 ms
71,676 KB
testcase_22 AC 91 ms
71,608 KB
testcase_23 AC 88 ms
71,788 KB
testcase_24 AC 90 ms
71,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        line = input().rstrip('\n')
        grid.append(line)

    d = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    inf = float('inf')
    que = deque()
    que.append((0, 0))
    seen = [[inf] * W for _ in range(H)]
    seen[0][0] = 0
    while que:
        h, w = que.popleft()
        for dh, dw in d:
            h_new, w_new = h+dh, w+dw
            if 0 <= h_new < H and 0 <= w_new < W:
                if seen[h_new][w_new] > 10**9:
                    que.append((h_new, w_new))
                if grid[h_new][w_new] == '.':
                    seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1)
                else:
                    seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1 + h_new + w_new)
    print(seen[-1][-1])


if __name__ == '__main__':
    main()
0