結果
問題 |
No.3063 Circle Balancing
|
ユーザー |
![]() |
提出日時 | 2025-06-12 12:59:16 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,100 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 67,536 KB |
最終ジャッジ日時 | 2025-06-12 13:05:53 |
合計ジャッジ時間 | 4,107 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 27 |
ソースコード
from collections import deque # Read input R, C = map(int, input().split()) sy, sx = map(int, input().split()) gy, gx = map(int, input().split()) # Convert to 0-based indices sy -= 1 sx -= 1 gy -= 1 gx -= 1 # Read grid grid = [input().strip() for _ in range(R)] # Directions: up, down, left, right dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] # Initialize distance array dist = [[-1] * C for _ in range(R)] q = deque() # Start BFS from the start position dist[sy][sx] = 0 q.append((sy, sx)) found = False while q and not found: y, x = q.popleft() # Check if current position is the goal if y == gy and x == gx: print(dist[y][x]) found = True break # Explore all four directions for i in range(4): ny = y + dy[i] nx = x + dx[i] # Check if the next position is within bounds if 0 <= ny < R and 0 <= nx < C: # Check if the cell is passable and not visited if grid[ny][nx] == '.' and dist[ny][nx] == -1: dist[ny][nx] = dist[y][x] + 1 q.append((ny, nx))