classSolution:deflatestDayToCross(self,row:int,col:int,cells: List[List[int]]) ->int:defcan(d): visited =set() q = collections.deque([(0,j) for j inrange(col)])for x, y in cells[:d]: visited.add((x-1, y-1))while q: x,y = q.popleft()if (x,y) in visited:continue visited.add((x,y))if x == row -1:returnTruefor dx, dy in [(1,0), (-1,0), (0,1), (0,-1)]:if0<= x + dx < row and0<= y + dy < col: q.append((x+dx, y+dy))returnFalse l, r =0, row * colwhile l <=r : mid = (l+r)//2ifcan(mid): l = mid +1else: r = mid -1return r