結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 17:18:29 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 786 bytes |
| 記録 | |
| コンパイル時間 | 701 ms |
| コンパイル使用メモリ | 20,824 KB |
| 実行使用メモリ | 56,632 KB |
| 最終ジャッジ日時 | 2026-04-18 17:19:08 |
| 合計ジャッジ時間 | 34,305 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 85 |
ソースコード
import sys
from collections import deque
readline = sys.stdin.readline
input_value = readline().split()
H = int(input_value[0])
W = int(input_value[1])
grid = [None] * H
for h in range(H):
fragment_grid = readline().split()
grid.append(fragment_grid)
dist = [[-1] * W for _ in range(H)]
queue = deque()
dist[0][0] = 0
queue.append((0,0))
dy = [-1, 1, 0, 0]
dx = [0, 0, -1, 1]
ans = H + W
while queue:
y, x = queue.popleft()
if y == H - 1 and x == W - 1:
ans = dist[y][x]
break
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= ny < H and 0 <= nx < W:
if grid[ny][nx] == '.' and dist[ny][nx] == -1:
dist[ny][nx] = dist[y][x] + 1
queue.append((ny, nx))
print(ans)