結果
| 問題 |
No.3063 Circle Balancing
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 20:55:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,133 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 82,068 KB |
| 実行使用メモリ | 67,452 KB |
| 最終ジャッジ日時 | 2025-04-15 20:58:44 |
| 合計ジャッジ時間 | 3,191 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 27 |
ソースコード
import sys
from collections import deque
R, C = map(int, sys.stdin.readline().split())
sy, sx = map(int, sys.stdin.readline().split())
gy, gx = map(int, sys.stdin.readline().split())
start_y = sy - 1
start_x = sx - 1
goal_y = gy - 1
goal_x = gx - 1
grid = []
for _ in range(R):
grid.append(sys.stdin.readline().strip())
distance = [[-1 for _ in range(C)] for _ in range(R)]
queue = deque()
distance[start_y][start_x] = 0
if start_y == goal_y and start_x == goal_x:
print(0)
sys.exit()
queue.append((start_y, start_x))
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
found = False
while queue:
y, x = queue.popleft()
current_dist = distance[y][x]
for dy, dx in directions:
ny = y + dy
nx = x + dx
if 0 <= ny < R and 0 <= nx < C:
if grid[ny][nx] == '.' and distance[ny][nx] == -1:
distance[ny][nx] = current_dist + 1
if ny == goal_y and nx == goal_x:
print(distance[ny][nx])
found = True
break
queue.append((ny, nx))
if found:
break
lam6er