結果
問題 |
No.3063 Circle Balancing
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:15:31 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,303 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 65,664 KB |
最終ジャッジ日時 | 2025-06-12 18:16:20 |
合計ジャッジ時間 | 3,317 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 27 |
ソースコード
import sys from collections import deque R, C = map(int, sys.stdin.readline().split()) sy, sx = map(int, sys.stdin.readline().split()) gy, gx = map(int, sys.stdin.readline().split()) # Convert to 0-based indices sy -= 1 sx -= 1 gy -= 1 gx -= 1 maze = [] for _ in range(R): row = sys.stdin.readline().strip() maze.append(list(row)) # Initialize distance matrix with -1 (unvisited) dist = [[-1 for _ in range(C)] for _ in range(R)] dist[sy][sx] = 0 queue = deque() queue.append((sy, sx)) # Directions: up, down, left, right directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] while queue: y, x = queue.popleft() current_distance = dist[y][x] for dy, dx in directions: ny = y + dy nx = x + dx # Check if within bounds if 0 <= ny < R and 0 <= nx < C: # Check if the cell is passable and not visited if maze[ny][nx] == '.' and dist[ny][nx] == -1: dist[ny][nx] = current_distance + 1 # Check if reached the goal if ny == gy and nx == gx: print(dist[ny][nx]) sys.exit() queue.append((ny, nx)) # According to the problem statement, the goal is always reachable, so this line is theoretically unreachable print(-1)