結果
| 問題 | No.3679 なんかでっかい虫リターンズ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-06 21:59:06 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 118 ms / 2,000 ms |
| + 43µs | |
| コード長 | 1,702 bytes |
| 記録 | |
| コンパイル時間 | 2,024 ms |
| コンパイル使用メモリ | 95,608 KB |
| 実行使用メモリ | 95,540 KB |
| 最終ジャッジ日時 | 2026-09-06 21:59:15 |
| 合計ジャッジ時間 | 4,687 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
H, W = map(int, input().split())
si, sj = map(int, input().split())
si -= 1
sj -= 1
r1, c1, r2, c2 = map(int, input().split())
r1 -= 1
c1 -= 1
r2 -= 1
c2 -= 1
ti, tj = map(int, input().split())
ti -= 1
tj -= 1
from collections import deque
que = deque()
dij = [(1,0),(0,1),(-1,0),(0,-1)]
musi = set()
for i in range(r1, r2+1):
for j in range(c1, c2+1):
musi.add((i,j))
visited = set()
que.append((si,sj,0))
visited.add((si,sj))
while que:
nowi, nowj, d = que.popleft()
if (nowi, nowj) in musi:
d0 = d
break
for di, dj in dij:
toi, toj = nowi+di, nowj+dj
if toi < 0 or toi >= H or toj < 0 or toj >= W:
continue
if (toi,toj) not in visited:
visited.add((toi,toj))
que.append((toi, toj, d+1))
visited = set()
que = deque()
que.append((nowi, nowj, 0))
visited.add((nowi, nowj))
while que:
nowi, nowj, d = que.popleft()
if (nowi, nowj) == (ti, tj):
d1 = d
break
for di, dj in dij:
toi, toj = nowi+di, nowj+dj
if toi < 0 or toi >= H or toj < 0 or toj >= W:
continue
if (toi,toj) not in visited:
visited.add((toi,toj))
que.append((toi, toj, d+1))
visited = set()
que = deque()
que.append((nowi, nowj, 0))
visited.add((nowi, nowj))
while que:
nowi, nowj, d = que.popleft()
if (nowi, nowj) == (si, sj):
d2 = d
break
for di, dj in dij:
toi, toj = nowi+di, nowj+dj
if toi < 0 or toi >= H or toj < 0 or toj >= W:
continue
if (toi,toj) not in visited:
visited.add((toi,toj))
que.append((toi, toj, d+1))
# print(musi)
print(d0+d1+d2)