結果
問題 |
No.3063 Circle Balancing
|
ユーザー |
![]() |
提出日時 | 2025-03-26 15:44:25 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,355 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 67,448 KB |
最終ジャッジ日時 | 2025-03-26 15:44:36 |
合計ジャッジ時間 | 4,144 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 27 |
ソースコード
import sys from collections import deque def main(): 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 # Read the maze maze = [] for _ in range(R): line = sys.stdin.readline().strip() maze.append(list(line)) # Initialize distance matrix with -1 (unvisited) dist = [[-1 for _ in range(C)] for _ in range(R)] dist[sy][sx] = 0 # Directions: up, down, left, right dy = [-1, 1, 0, 0] dx = [0, 0, -1, 1] q = deque() q.append((sy, sx)) while q: y, x = q.popleft() current_dist = dist[y][x] for i in range(4): ny = y + dy[i] nx = x + dx[i] if 0 <= ny < R and 0 <= nx < C: if maze[ny][nx] == '.' and dist[ny][nx] == -1: dist[ny][nx] = current_dist + 1 q.append((ny, nx)) if ny == gy and nx == gx: print(dist[ny][nx]) return # According to the problem statement, the path always exists. print(dist[gy][gx]) if __name__ == "__main__": main()