Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
                m[i][j] = 0
    
    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    q = deque([])
    l = [input() for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
    
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    q = deque([])
    l = [input() for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
    
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for i in range(4):
            x1, y1 = x + dx[i], y + dy[i]
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for i in range(4):
            x1, x2 = x + dx[i], y + dy[i]
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for y1, x1 in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[H*W]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for y1, x1 in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] > cost+1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    used = [[0]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)

    while q:
        y, x, cost = q.popleft()
        used[y][x] = 1

        for y1, x1 in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0<=x1<W and 0<=y1<H):
                continue
            if used[y1][x1]:
                continue
            q.append((y1, x1, cost+1))

    print(cost)


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    dp = [[False]*W for _ in range(H)]
    candidate = []

    for i in range(H):
        for j, s in enumerate(input()):
            if s=="#":
                dp[i][j] = True
                candidate.append((i, j))

    q = deque([(c, 0) for c in candidate])
    while q:
        (y, x), cost = q.popleft()
        dp[y][x] = True

        for y1, x1 in [(y+1, x), (y-1, x), (y, x-1), (y, x+1)]:
            if not (0<=y1<H and 0<=x1<W):
                continue
            if dp[y1][x1]:continue
            q.append(((y1, x1), cost+1))

    print(cost)


if __name__ == "__main__":
    solve()


Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()