結果
問題 | No.3063 Circle Balancing |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:18:22 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,037 bytes |
コンパイル時間 | 132 ms |
コンパイル使用メモリ | 82,592 KB |
実行使用メモリ | 67,508 KB |
最終ジャッジ日時 | 2025-03-31 17:18:56 |
合計ジャッジ時間 | 3,973 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 27 |
ソースコード
from collections import dequeimport sysdef 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())maze = [sys.stdin.readline().strip() for _ in range(R)]# Convert to 0-based indicessy -= 1sx -= 1gy -= 1gx -= 1# Initialize BFSdist = [[-1 for _ in range(C)] for _ in range(R)]dist[sy][sx] = 0q = deque()q.append((sy, sx))# Directions: up, down, left, rightdirections = [(-1, 0), (1, 0), (0, -1), (0, 1)]while q:y, x = q.popleft()if y == gy and x == gx:print(dist[y][x])returnfor dy, dx in directions:ny = y + dynx = x + dxif 0 <= ny < R and 0 <= nx < C:if maze[ny][nx] == '.' and dist[ny][nx] == -1:dist[ny][nx] = dist[y][x] + 1q.append((ny, nx))if __name__ == "__main__":main()