結果

問題 No.2897 2集合間距離
ユーザー urunea
提出日時 2025-04-29 16:18:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 866 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 82,524 KB
実行使用メモリ 165,780 KB
最終ジャッジ日時 2025-04-29 16:18:15
合計ジャッジ時間 7,790 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
N_mem=[]
for i in range(N):
    x,y=(int(x) for x in input().split())
    N_mem.append([999-y,x])

M=int(input())
M_mem=set()
for i in range(M):
    x,y=(int(x) for x in input().split())
    M_mem.add((999-y,x))

visited=[[False]*(10**3) for i in range(10**3)]

stack=[]
for i,j in N_mem:
    visited[i][j] = True
    stack.append([i,j])

next_move=[]
move=[[1,0],[-1,0],[0,1],[0,-1]]
ans=0
found=False
while stack:
    for i in stack:
        if tuple(i) in M_mem:
            found=True
            break
        for j in move:
            if 0 <= i[0]+j[0] < 10**3 and 0 <= i[1]+j[1] < 10*3 and visited[i[0]+j[0]][i[1]+j[1]] == False:
                visited[i[0]+j[0]][i[1]+j[1]] = True
                next_move.append([i[0]+j[0], i[1]+j[1]])
    
    if found:
        print(ans)
        exit()

    ans += 1
    stack, next_move = next_move, []
0