Problem:


Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3



Sample input:
3 3
...
.#.
...


Sample output:
2

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflt_fromleft = 10**9
                
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = beflt_fromleft+1
            
            min_ = min(fromtop,fromleft)
            datamaplt[ii][jj] = min_
            beflt_fromleft = min_
        else:
            beflt_fromleft = 0
            

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrt_fromright = 10**9
            fromtop = datamaprt[ii-1][jj]+1
            fromright = befrt_fromright+1
            
            min_ = min(fromtop,fromright)
            datamaprt[ii][jj] = min_
            befrt_fromright = min_
        else:
            befrt_fromright = 0

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflb_fromleft = 10**9
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = beflb_fromleft+1
            min_ = min(frombottom,fromleft)
            datamaplb[ii][jj] = min_
            beflb_fromleft = min_
        else:
            beflb_fromleft = 0

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrb_fromright= 10**9
            frombottom = datamaprb[ii+1][jj]+1
            fromright = befrb_fromright+1
            min_= min(fromright,frombottom)
            datamaprb[ii][jj] = min_
        else:
            befrb_fromright= 0
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflt_fromleft = 10**9
                
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = beflt_fromleft+1
            
            min_ = min(fromtop,fromleft)
            datamaplt[ii][jj] = min_
            beflt_fromleft = min_
        else:
            beflt_fromleft = 0
            

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrt_fromright = 10**9
            fromtop = datamaprt[ii-1][jj]+1
            fromright = befrt_fromright+1
            
            min_ = min(fromtop,fromright)
            datamaprt[ii][jj] = min_
            befrt_fromright = min_
        else:
            befrt_fromright = 0

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflb_fromleft = 10**9
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = beflb_fromleft+1
            min_ = min(frombottom,fromleft)
            datamaplb[ii][jj] = min_
            beflb_fromleft = min_
        else:
            beflb_fromleft = 0

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrb_fromright= 10**9
            frombottom = datamaprb[ii+1][jj]+1
            fromright = befrb_fromright+1
            min_= min(fromright,frombottom)
            datamaprb[ii][jj] = min_
        else:
            befrb_fromright= 0
            
ans = 0  

            
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflt_fromleft = 10**9
                
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = beflt_fromleft+1
            
            min_ = min(fromtop,fromleft)
            datamaplt[ii][jj] = min_
            beflt_fromleft = min_
        else:
            beflt_fromleft = 0
            

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrt_fromright = 10**9
            fromtop = datamaprt[ii-1][jj]+1
            fromright = befrt_fromright+1
            
            min_ = min(fromtop,fromright)
            datamaprt[ii][jj] = min_
            befrt_fromright = min_
        else:
            befrt_fromright = 0

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == 0:
                beflb_fromleft = 10**9
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = beflb_fromleft+1
            min_ = min(frombottom,fromleft)
            datamaplb[ii][jj] = min_
            beflb_fromleft = min_
        else:
            beflb_fromleft = 0

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            if j == w-1:
                befrb_fromright= 10**9
            frombottom = datamaprb[ii+1][jj]+1
            fromright = befrb_fromright+1
            min_= min(fromright,frombottom)
            datamaprb[ii][jj] = min_
        else:
            befrb_fromright= 0
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(0)

Submission status: Wrong Answer

Solution code:
def solve():
    from collections import deque
    H,W = map(int, input().split())
    A = [ list(input()) for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]
 
    
    q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                q.append((0,h,w))
                A[h][w] = "."
    while q:
        num,h,w = q.popleft()
        if HMANY[h][w] > num and A[h][w] == ".":
            HMANY[h][w] = num
            A[h][w] = "#"
 
            if h+1 <H and A[h+1][w] == ".":
                q.append( (num+1,h+1,w))
            if w+1 <W and A[h][w+1] == ".":
                q.append((num+1,h,w+1))
            if 0<=h-1 and A[h-1][w] == ".":
                q.append((num+1,h-1,w))
            if 0<=w-1 and A[h][w-1] == ".":
                q.append((num+1,h,w-1))
 
    ans = 0

    print(ans)
 
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    #data.append([])
    #data[i+1].append(10**9)
    data.append(list(dummylist0))
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    """for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)"""
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i][j+1] = 1

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(0)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

dummylist = []
for _ in range(w+2):
    dummylist.append(10**9)

dummylist0 = []
dummylist0.append(10**9)
for _ in range(w):
    dummylist0.append(0)
dummylist0.append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    
    datamaplt.append(list(dummylist0))
    datamaprt.append(list(dummylist0))
    datamaplb.append(list(dummylist0))
    datamaprb.append(list(dummylist0))
    
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
            
    data[i+1].append(10**9)

data.append(list(dummylist))
datamaplt.append(list(dummylist))
datamaprt.append(list(dummylist))
datamaplb.append(list(dummylist))
datamaprb.append(list(dummylist))
""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(0)

Submission status: Wrong Answer

Solution code:
from collections import deque

h,w = map(int,input().split())
hw = [input() for i in range(h)]
#for i in range(h):
#    hw.append(input())

# used = [True]*h*w
isWhite = [[True]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i,j,0])# h, w, step count
            isWhite[i][j] = False

res = 0
while len(queue) > 0:
    pos = queue.popleft()
    if pos[0] > 0 and isWhite[pos[0]-1][pos[1]]:
        queue.append([pos[0]-1, pos[1], pos[2]+1])
        isWhite[pos[0]-1][pos[1]] = False
    if pos[0] < h-1 and isWhite[pos[0]+1][pos[1]]:
        queue.append([pos[0]+1, pos[1], pos[2]+1])
        isWhite[pos[0]+1][pos[1]] = False
    if pos[1] > 0 and isWhite[pos[0]][pos[1]-1]:
        queue.append([pos[0], pos[1]-1, pos[2]+1])
        isWhite[pos[0]][pos[1]-1] = False
    if pos[1] < w-1 and isWhite[pos[0]][pos[1]+1]:
        queue.append([pos[0], pos[1]+1, pos[2]+1])
        isWhite[pos[0]][pos[1]+1] = False
        print(queue)
    res = pos[2]
print(res)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = datamaplt[ii][jj]
        if min_temp > ans:
            ans =  min_temp
            
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

""" data preparation """
data = []
datamaplt = []
datamaprt = []
datamaplb = []
datamaprb = []

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[0].append(10**9)
    datamaplt[0].append(10**9)
    datamaprt[0].append(10**9)
    datamaplb[0].append(10**9)
    datamaprb[0].append(10**9)

for i in range(h):
    data.append([])
    data[i+1].append(10**9)
    datamaplt.append([])
    datamaplt[i+1].append(10**9)
    datamaprt.append([])
    datamaprt[i+1].append(10**9)
    datamaplb.append([])
    datamaplb[i+1].append(10**9)
    datamaprb.append([])
    datamaprb[i+1].append(10**9)
    for  j in range(w):
        if data_t[i][j] == "#":
            data[1+i].append(1)
        else:
            data[1+i].append(0)
        datamaplt[1+i].append(0)
        datamaprt[1+i].append(0)
        datamaplb[1+i].append(0)
        datamaprb[1+i].append(0)
    data[i+1].append(10**9)
    datamaplt[i+1].append(10**9)
    datamaprt[i+1].append(10**9)
    datamaplb[i+1].append(10**9)
    datamaprb[i+1].append(10**9)

data.append([])
datamaplt.append([])
datamaprt.append([])
datamaplb.append([])
datamaprb.append([])
for _ in range(w+2):
    data[h+1].append(10**9)
    datamaplt[h+1].append(10**9)
    datamaprt[h+1].append(10**9)
    datamaplb[h+1].append(10**9)
    datamaprb[h+1].append(10**9)

""" data preparation """




for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaplt[ii-1][jj]+1
            fromleft = datamaplt[ii][jj-1]+1
            datamaplt[ii][jj] = min(fromtop,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            fromtop = datamaprt[ii-1][jj]+1
            fromright = datamaprt[ii][jj+1]+1
            datamaprt[ii][jj] = min(fromtop,fromright)

for i in range(h-1,-1,-1):
    for  j in range(w):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaplb[ii+1][jj]+1
            fromleft = datamaplb[ii][jj-1]+1
            datamaplb[ii][jj] = min(frombottom,fromleft)

    for  j in range(w-1,-1,-1):
        ii = i+1
        jj = j+1
        if data[ii][jj] == 0:
            frombottom = datamaprb[ii+1][jj]+1
            fromright = datamaprb[ii][jj+1]+1
            datamaprb[ii][jj] = min(fromright,frombottom)
            
ans = 0  
for i in range(h):
    for  j in range(w):
        ii = i+1
        jj = j+1
        min_temp = min(datamaplt[ii][jj],datamaprt[ii][jj],datamaplb[ii][jj],datamaprb[ii][jj])
        if min_temp > ans:
            ans =  min_temp
            
print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    H,W=map(int,input().split(' '))
    max_value = H+W
    values =[]
    for i in range(H):
      values.append([0 if i == '#' else max_value for i in list(input())])
    values = np.array(values)

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

    print(np.max(values))
solve()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S = []
for _ in range(H):
    S.append(input())

li1=[]

for i in range(H):
    li1=[[i,j] for j in range(W) if S[i][j]=="#"]

e=H*W
f=0

for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            e=H*W
            for k in li1:
                ca=abs(i-k[0])+abs(j-k[1])
                e=min(e,ca)
            f=max(f,e)

print(f)

Submission status: Wrong Answer

Solution code:
from collections import deque
H,W = map(int,input().split())
INF = 10**10
grid = [[INF for i in range(W)] for i in range(H)]
queue = deque()
for h in range(H):
  a = list(input())
  for w in range(W):
    if a[w]=='#':
      queue.append([h,w])
while len(queue)!=0:
  print(queue.popleft())

Submission status: Wrong Answer

Solution code:
from collections import deque
H,W = map(int,input().split())
INF = 10**10
grid = [[INF for i in range(W)] for i in range(H)]
queue = deque()
for h in range(H):
  a = list(input())
  for w in range(W):
    if a[w]=='#':
      grid[h][w] = 0
      if 0<=h-1:
        queue.append([h-1,w])
      if h+1<H:
        queue.append([h+1,w])
      if 0<=w-1:
        queue.append([h,w-1])
      if w+1<W:
        queue.append([h,w+1])
print(queue)

Submission status: Wrong Answer

Solution code:
import queue
def solve():
    cnt=0
    black=[]
    H,W=list(map(int,input().split(' ')))
    dark = []
    q = queue.Queue()
    for i in range(H):
        dark.append(list(input()))
    for i in range(H):
        for j in range(W):
            if dark[i][j] =='#':
                q.put([i,j])
                black.append([i,j])

    while 1:
        cnt +=1
        for i in range(q.qsize()):
            h,w=q.get()
            if h-1 >= 0 and not([h-1,w] in black):
                black.append([h-1,w])
                q.put([h-1,w])
            if h+1 < H and not([h+1,w] in black) :
                black.append([h+1,w])
                q.put([h+1,w])
            if w-1 >= 0 and not([h,w-1] in black):
                black.append([h,w-1])
                q.put([h,w-1])
            if w+1 < W and not ([h,w+1] in black):
                black.append([h,w+1])
                q.put([h,w+1])
        if len(black) == H*W:
            break

    return cnt

print(solve())

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#!/usr/bin/env python3

from collections import deque

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = deque()

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            q.append( (x, y, 0) )
            is_visited[y][x] = True

while q:
    # queue の先頭を取り出す
    x, y, cnt = q.popleft()
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]

        if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
            continue

        q.append( (ny, nx, cnt+1) )
        is_visited[ny][nx] = True

print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#!/usr/bin/env python3

from collections import deque

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = deque()

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            q.append( (x, y, 0) )
            is_visited[y][x] = True

ans = 0
while q:
    # queue の先頭を取り出す
    x, y, cnt = q.popleft()
    ans = max(ans, cnt)
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]

        if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
            continue

        q.append( (ny, nx, cnt+1) )
        is_visited[ny][nx] = True

print(ans)

Submission status: Wrong Answer

Solution code:
h, w =(int(i) for i in input().split())
a=[input() for i in range(h)]
data=[[0]*w for i in range(h)]
checked=[[False]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			checked[i][j]=True
			data[i][j]=99999
			for k in range(4):
				if j+dx[k] < 0 or j+dx[k] > w-1 or i+dy[k] < 0 or i+dy[k] >h-1:
					continue
				data[i+dy[k]][j+dx[k]]+=1
				checked[i+dy[k]][j+dx[k]]=True

def exist0(data):
	h=len(data)
	w=len(data[0])
	for i in range(h):
		for j in range(w):
			if data[i][j] == 0:
				return True
	return False
	
n=1
while exist0(data):
	for i in range(h):
		for j in range(w):
			if data[i][j]==n:
				for k in range(4):
					if j+dx[k] < 0 or j+dx[k] > w-1 or i+dy[k] < 0 or i+dy[k] >h-1:
						continue
					if checked[i+dy[k]][j+dx[k]]:
						continue
					data[i+dy[k]][j+dx[k]]+=n+1
					checked[i+dy[k]][j+dx[k]]=True
	n+=1
	
print(n)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#!/usr/bin/env python3

import queue

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = queue.Queue()

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            q.put( (x, y, 0) )
            is_visited[y][x] = True

ans = 0
while not q.empty():
    # queue の先頭を取り出す
    x, y, cnt = q.get()
    ans = max(ans, cnt)
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]

        if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
            continue

        q.put( (ny, nx, cnt+1) )
        is_visited[ny][nx] = True

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#!/usr/bin/env python3

import queue

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

# 黒マスを列挙 O(H*W)
black_grid = []

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            black_grid += [ (x, y) ]

q = queue.Queue()

# 各黒マスを queue に入れる
for point in black_grid:
    q.put(point)

ans = 0

while not q.empty():
    is_all_black = True
    # 各黒マスから BFS
    for _ in range(q.qsize()):
        # queue の先頭を取り出す
        x, y = q.get()
        # 4方向にループ
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]

            if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
                continue

            is_all_black = False
            q.put( (ny, nx) )
            is_visited[ny][nx] = True

    if not is_all_black:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
X = [int(i) for i in input().split()]
queue = [(i,j) for i in range(X[0]) for j,s in enumerate(input()) if s=="#"]
end = []
for n in range(0,100):
    tmp = []
    end += queue
    for q in queue:
        i,j = q[0],q[1]
        up = max(0, i-1)
        down = min(i+1, X[0]-1)
        left = max(0, j-1)
        right = min(j+1, X[1]-1)
        tmp += [t for t in [(up,j),(down,j),(i,left),(i,right)] if t not in end]
    queue = list(set(tmp))
    if len(queue) == 0:
        break
print(n)

Submission status: Wrong Answer

Solution code:
X = [int(i) for i in input().split()]
queue = [(i,j) for i in range(X[0]) for j,s in enumerate(input()) if s=="#"]
end = []