結果

問題 No.2897 2集合間距離
ユーザー urunea
提出日時 2025-04-29 16:05:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 3,393 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 165,588 KB
最終ジャッジ日時 2025-04-29 16:06:10
合計ジャッジ時間 10,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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([x,y])

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

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

stack=[]
for x,y in N_mem:
    visited[x][y] = True
    stack.append([x,y])

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