結果
| 問題 |
No.3063 Circle Balancing
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:48:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,082 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 82,732 KB |
| 実行使用メモリ | 67,716 KB |
| 最終ジャッジ日時 | 2025-06-12 14:52:16 |
| 合計ジャッジ時間 | 3,516 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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())
sy -= 1
sx -= 1
gy -= 1
gx -= 1
grid = []
for _ in range(R):
line = sys.stdin.readline().strip()
grid.append(list(line))
distance = [[-1 for _ in range(C)] for _ in range(R)]
distance[sy][sx] = 0
queue = deque()
queue.append((sy, sx))
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while queue:
y, x = queue.popleft()
if y == gy and x == gx:
print(distance[y][x])
return
for dy, dx in directions:
new_y = y + dy
new_x = x + dx
if 0 <= new_y < R and 0 <= new_x < C:
if grid[new_y][new_x] == '.' and distance[new_y][new_x] == -1:
distance[new_y][new_x] = distance[y][x] + 1
queue.append((new_y, new_x))
if __name__ == "__main__":
main()
gew1fw