Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = []
  result = 0

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue.extend((x, y, 1) for x, v in enumerate(values[-1]) if v == 0)

  while len(queue) > 0:
    x, y, v = queue.pop(0)
    result = v - 1

    if x > 0 and values[y][x - 1] > v:
      values[y][x - 1] = v
      queue.append((x - 1, y, v + 1))

    if x < width - 1 and values[y][x + 1] > v:
      values[y][x + 1] = v
      queue.append((x + 1, y, v + 1))

    if y > 0 and values[y - 1][x ] > v:
      values[y - 1][x] = v
      queue.append((x, y - 1, v + 1))

    if y < height - 1 and values[y + 1][x] > v:
      values[y + 1][x] = v
      queue.append((x, y + 1, v + 1))

  print(result, flush=True)


if __name__ == '__main__':
  main()



Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

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

  values = numpy.array(values)

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

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

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

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

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = []

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue.extend((x, y, 1) for x, v in enumerate(values[-1]) if v == 0)

  while len(queue) > 0:
    x, y, v = queue.pop(0)

    if x > 0 and values[y][x - 1] > v:
      values[y][x - 1] = v
      queue.append((x - 1, y, v + 1))

    if x < width - 1 and values[y][x + 1] > v:
      values[y][x + 1] = v
      queue.append((x + 1, y, v + 1))

    if y > 0 and values[y - 1][x ] > v:
      values[y - 1][x] = v
      queue.append((x, y - 1, v + 1))

    if y < height - 1 and values[y + 1][x] > v:
      values[y + 1][x] = v
      queue.append((x, y + 1, v + 1))

  print(max(max(v) for v in values), flush=True)


if __name__ == '__main__':
  main()



Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

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

  values = numpy.array(values)

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

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

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

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

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = []

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue.extend((x, y) for x, v in enumerate(values[-1]) if v == 0)

  targets = set(queue)

  while len(queue) > 0:
    x, y = queue.pop()
    v = values[y][x] + 1

    targets.remove((x, y))

    if x > 0 and values[y][x - 1] > v:
      values[y][x - 1] = v

      if (x - 1, y) not in targets:
        queue.append((x - 1, y))
        targets.add((x - 1, y))

    if x < width - 1 and values[y][x + 1] > v:
      values[y][x + 1] = v

      if (x + 1, y) not in targets:
        queue.append((x + 1, y))
        targets.add((x + 1, y))

    if y > 0 and values[y - 1][x ] > v:
      values[y - 1][x] = v

      if (x , y - 1) not in targets:
        queue.append((x, y - 1))
        targets.add((x, y - 1))

    if y < height - 1 and values[y + 1][x] > v:
      values[y + 1][x] = v

      if (x , y + 1) not in targets:
        queue.append((x, y + 1))
        targets.add((x, y + 1))

  print(max(max(v) for v in values), flush=True)


if __name__ == '__main__':
  main()



Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

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

  values = numpy.array(values)

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

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

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

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

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = set()

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue |= set((x, y) for x, v in enumerate(values[-1]) if v == 0)

  while len(queue) > 0:
    x, y = queue.pop()
    v = values[y][x] + 1

    if x > 0 and values[y][x - 1] > v:
      values[y][x - 1] = v
      queue.add((x - 1, y))

    if x < width - 1 and values[y][x + 1] > v:
      values[y][x + 1] = v
      queue.add((x + 1, y))

    if y > 0 and values[y - 1][x ] > v:
      values[y - 1][x] = v
      queue.add((x, y - 1))

    if y < height - 1 and values[y + 1][x] > v:
      values[y + 1][x] = v
      queue.add((x, y + 1))

  print(max(max(v) for v in values), flush=True)


if __name__ == '__main__':
  main()



Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

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

  values = numpy.array(values)

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

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

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

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

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = []

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue.extend((x, y) for x, v in enumerate(values[-1]) if v == 0)

  while len(queue) > 0:
    x, y = queue.pop(0)
    v = values[y][x] + 1

    if x > 0 and values[y][x - 1] > v:
      values[y][x - 1] = v
      queue.append((x - 1, y))

    if x < width - 1 and values[y][x + 1] > v:
      values[y][x + 1] = v
      queue.append((x + 1, y))

    if y > 0 and values[y - 1][x ] > v:
      values[y - 1][x] = v
      queue.append((x, y - 1))

    if y < height - 1 and values[y + 1][x] > v:
      values[y + 1][x] = v
      queue.append((x, y + 1))

  print(max(max(v) for v in values), flush=True)


if __name__ == '__main__':
  main()



Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

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

  values = numpy.array(values)

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

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

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

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

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()