結果
| 問題 | No.2897 2集合間距離 |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-11-03 04:35:59 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 378 ms / 3,500 ms |
| コード長 | 559 bytes |
| 記録 | |
| コンパイル時間 | 382 ms |
| コンパイル使用メモリ | 85,280 KB |
| 実行使用メモリ | 122,072 KB |
| 最終ジャッジ日時 | 2026-05-06 02:01:08 |
| 合計ジャッジ時間 | 8,494 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
DP=[[1<<30]*1010 for i in range(1010)]
Q=deque()
N=int(input())
for i in range(N):
x,y=map(int,input().split())
DP[x][y]=0
Q.append((x,y))
while Q:
x,y=Q.popleft()
for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
if 0<=z<1010 and 0<=w<1010:
if DP[z][w]>DP[x][y]+1:
DP[z][w]=DP[x][y]+1
Q.append((z,w))
M=int(input())
ANS=1<<30
for i in range(M):
x,y=map(int,input().split())
ANS=min(ANS,DP[x][y])
print(ANS)
titia