結果
問題 |
No.3063 Circle Balancing
|
ユーザー |
![]() |
提出日時 | 2025-04-15 20:56:06 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,391 bytes |
コンパイル時間 | 200 ms |
コンパイル使用メモリ | 82,712 KB |
実行使用メモリ | 67,520 KB |
最終ジャッジ日時 | 2025-04-15 20:59:28 |
合計ジャッジ時間 | 3,095 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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 grid = [sys.stdin.readline().strip() for _ in range(R)] # 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 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] q = deque() q.append((sy, sx)) while q: y, x = q.popleft() # Check if current position is the goal if y == gy and x == gx: print(dist[y][x]) return for dy, dx in directions: ny = y + dy nx = x + dx # Check if the new position is within bounds if 0 <= ny < R and 0 <= nx < C: # Check if the cell is accessible and not visited if grid[ny][nx] == '.' and dist[ny][nx] == -1: dist[ny][nx] = dist[y][x] + 1 q.append((ny, nx)) # The problem states that the goal is reachable, so this line is theoretically unreachable print(-1) if __name__ == "__main__": main()