結果

問題 No.3504 Insert Maze
コンテスト
ユーザー detteiuu
提出日時 2026-08-19 22:57:28
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 645 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 236 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 155,136 KB
最終ジャッジ日時 2026-08-19 22:57:51
合計ジャッジ時間 21,961 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque

INF = 1<<60

direction = [(-1,0),(0,1),(1,0),(0,-1)]

H, W = map(int, input().split())
S = [input() for _ in range(H)]

que = deque()
que.append((0, 0))
visited = [[INF]*W for _ in range(H)]
visited[0][0] = 0
flag = False
while que:
    h, w = que.popleft()
    if H-2 <= h or W-2 <= w:
        flag = True
    for dh, dw in direction:
        nh, nw = h+dh, w+dw
        if 0<=nh<H and 0<=nw<W and S[nh][nw] != "#" and visited[nh][nw] == INF:
            visited[nh][nw] = visited[h][w]+1
            que.append((nh, nw))

if flag:
    print(min(visited[-1][-1], H+W-1))
else:
    print(min(visited[-1][-1], H+W))
0