結果
問題 |
No.2897 2集合間距離
|
ユーザー |
![]() |
提出日時 | 2024-11-03 04:35:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 611 ms / 3,500 ms |
コード長 | 559 bytes |
コンパイル時間 | 545 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 117,544 KB |
最終ジャッジ日時 | 2024-11-03 04:36:12 |
合計ジャッジ時間 | 11,923 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)