結果
| 問題 | No.3679 なんかでっかい虫リターンズ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-18 10:05:03 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 62 ms / 2,000 ms |
| + 229µs | |
| コード長 | 1,011 bytes |
| 記録 | |
| コンパイル時間 | 79 ms |
| コンパイル使用メモリ | 81,152 KB |
| 実行使用メモリ | 80,384 KB |
| 最終ジャッジ日時 | 2026-09-18 10:05:06 |
| 合計ジャッジ時間 | 2,692 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
from collections import deque
H, W = map(int, input().split())
A, B = map(lambda x: int(x)-1, input().split())
R1, C1, R2, C2 = map(lambda x: int(x)-1, input().split())
P, Q = map(lambda x: int(x)-1, input().split())
vector = [(1, 0), (0, 1), (-1, 0), (0, -1)]
dist1 = [[10**4]*W for _ in range(H)]
dist1[A][B] = 0
queue = deque()
queue.append((A, B))
while queue:
i, j = queue.popleft()
for vi, vj in vector:
if 0 <= i+vi < H and 0 <= j + vj < W and dist1[i+vi][j+vj] == 10**4:
dist1[i+vi][j+vj] = dist1[i][j] + 1
queue.append((i+vi, j+vj))
dist2 = [[10**4]*W for _ in range(H)]
dist2[P][Q] = 0
queue = deque()
queue.append((P, Q))
while queue:
i, j = queue.popleft()
for vi, vj in vector:
if 0 <= i+vi < H and 0 <= j + vj < W and dist2[i+vi][j+vj] == 10**4:
dist2[i+vi][j+vj] = dist2[i][j] + 1
queue.append((i+vi, j+vj))
ans = 10**18
for i in range(R1, R2+1):
for j in range(C1, C2+1):
ans = min(ans, dist1[i][j] + dist2[i][j] + dist2[A][B])
print(ans)