Buggy python submission (verdict: Time Limit Exceeded):
def make_daker(mas, H, W):
  #mas_new = [["." for i in range(W)] for j in range(H)]
  import copy
  mas_new = copy.deepcopy(mas)
  for i in range(H):
    for j in range(W):
      if mas[i][j] == "#":
        mas_new[i][j] = "#"
        if i-1 >= 0:
          mas_new[i-1][j] = "#"
        if i+1 < H:
          mas_new[i+1][j] = "#"
        if j-1 >= 0:
          mas_new[i][j-1] = "#"
        if j+1 < W:
          mas_new[i][j+1] = "#"
  return mas_new

def include_white(mas):
  for row in mas:
    if "." in row:
      return True
  return False

H, W = map(int, input().split())
mas = [[i for i in input()] for i in range(H)]

ans = 0

while include_white(mas) is True:
  mas = make_daker(mas, H, W)
  ans +=1
print(ans)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
# from time import perf_counter


def main():
    h, w = map(int, input().split())
    max_value = h + w
    gridmap = []

    for y in range(h):
        gridmap.append([0 if v == '#' else max_value for v in input().strip()])

    values = np.array(gridmap)

    for x in range(w - 1):
        values[:, x + 1] = np.minimum(values[:, x] + 1, values[:, x + 1])

    for x in range(w - 1, 0, -1):
        values[:, x - 1] = np.minimum(values[:, x] + 1, values[:, x - 1])

    for y in range(h - 1):
        values[y + 1, :] = np.minimum(values[y, :] + 1, values[y + 1, :])

    for y in range(h - 1, 0, -1):
        values[y - 1, :] = np.minimum(values[y, :] + 1, values[y - 1, :])

    print(np.max(values))


if __name__ == '__main__':
    # st = perf_counter()
    main()
    # ed = perf_counter()
    # print(ed - st)

Buggy python submission (verdict: Time Limit Exceeded):
def make_daker(mas, H, W):
  mas_new = [["." for i in range(W)] for j in range(H)]
  for i in range(H):
    for j in range(W):
      if mas[i][j] == "#":
        mas_new[i][j] = "#"
        if i-1 >= 0:
          mas_new[i-1][j] = "#"
        if i+1 < H:
          mas_new[i+1][j] = "#"
        if j-1 >= 0:
          mas_new[i][j-1] = "#"
        if j+1 < W:
          mas_new[i][j+1] = "#"
  return mas_new

def include_white(mas):
  for row in mas:
    if "." in row:
      return True
  return False

H, W = map(int, input().split())
mas = [[i for i in input()] for i in range(H)]

ans = 0

while include_white(mas) is True:
  mas = make_daker(mas, H, W)
  ans +=1
print(ans)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
# from time import perf_counter


def main():
    h, w = map(int, input().split())
    max_value = h + w
    gridmap = []

    for y in range(h):
        gridmap.append([0 if v == '#' else max_value for v in input().strip()])

    values = np.array(gridmap)

    for x in range(w - 1):
        values[:, x + 1] = np.minimum(values[:, x] + 1, values[:, x + 1])

    for x in range(w - 1, 0, -1):
        values[:, x - 1] = np.minimum(values[:, x] + 1, values[:, x - 1])

    for y in range(h - 1):
        values[y + 1, :] = np.minimum(values[y, :] + 1, values[y + 1, :])

    for y in range(h - 1, 0, -1):
        values[y - 1, :] = np.minimum(values[y, :] + 1, values[y - 1, :])

    print(np.max(values))


if __name__ == '__main__':
    # st = perf_counter()
    main()
    # ed = perf_counter()
    # print(ed - st)