from collections import deque
def bfs_kuoshang():
directions=[(1,0),(-1,0),(0,1),(0,-1)]
black_cell={(0,0),(2020,11),(11,14),(2000,2000)}
queue=deque(black_cell)
visited=black_cell.copy()
for _ in range(2020):
for _ in range(len(queue)):
x,y=queue.popleft()
for dx,dy in directions:
nx,ny=x+dx,y+dy
if (nx,ny) not in visited:
visited.add((nx,ny))
queue.append((nx,ny))
return len(visited)
print(bfs_kuoshang())
注意:运行内存有点大