結果
| 問題 |
No.3063 Circle Balancing
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:04:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,303 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,208 KB |
| 実行使用メモリ | 138,696 KB |
| 最終ジャッジ日時 | 2025-06-12 20:10:28 |
| 合計ジャッジ時間 | 4,869 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 27 |
ソースコード
from collections import deque
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
R = int(data[idx])
idx += 1
C = int(data[idx])
idx += 1
sy = int(data[idx]) - 1
idx += 1
sx = int(data[idx]) - 1
idx += 1
gy = int(data[idx]) - 1
idx += 1
gx = int(data[idx]) - 1
idx += 1
grid = []
for i in range(R):
grid.append(data[idx])
idx += 1
if sy == gy and sx == gx:
print(0)
return
directions = [ (-1, 0), (1, 0), (0, -1), (0, 1) ]
dist = [ [ -1 for _ in range(C) ] for _ in range(R) ]
q = deque()
q.append( (sy, sx) )
dist[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in directions:
ny = y + dy
nx = x + dx
if 0 <= ny < R and 0 <= nx < C:
if grid[ny][nx] == '.' and dist[ny][nx] == -1:
dist[ny][nx] = dist[y][x] + 1
if ny == gy and nx == gx:
print(dist[ny][nx])
return
q.append( (ny, nx) )
# According to problem statement, it's guaranteed to reach, so no need for this
print(-1)
if __name__ == "__main__":
main()
gew1fw