結果
| 問題 |
No.3063 Circle Balancing
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:02:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 917 bytes |
| コンパイル時間 | 202 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 67,592 KB |
| 最終ジャッジ日時 | 2025-06-12 13:08:07 |
| 合計ジャッジ時間 | 3,591 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 = [sys.stdin.readline().strip() for _ in range(R)]
dist = [[-1] * C for _ in range(R)]
q = deque()
q.append((sy, sx))
dist[sy][sx] = 0
dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
while q:
y, x = q.popleft()
if y == gy and x == gx:
print(dist[y][x])
return
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= ny < R and 0 <= nx < C:
if grid[ny][nx] == '.' and dist[ny][nx] == -1:
dist[ny][nx] = dist[y][x] + 1
q.append((ny, nx))
if __name__ == "__main__":
main()
gew1fw