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: Runtime Error

Solution code:
import numpy as np

H, W = map(int, input().split())

x = []
for h in range(H):
    line = list(input())
    for _ in line:
        for value in _:
            x.append(value)
x = np.array(x)
x = x.reshape(num_i, num_j)

count = 0
boolean = True
while (boolean):
    count += 1
    i_arr = []
    j_arr = []
    for i in range(num_i):
        for j in range(num_j):
            if (x[i][j] == "#"):
                i_arr.append(i)
                j_arr.append(j)
    for i, j in zip(i_arr, j_arr):
        if (i == 0) & (j == 0):
            x[1][0] = "#"
            x[0][1] = "#"
        elif (i == num_i - 1) & (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i][j - 1] = "#"
        elif (i == num_i - 1) & (j == 0):
            x[i - 1][0] = "#"
            x[i][1] = "#"
        elif (i == 0) & (j == num_j - 1):
            x[1][j] = "#"
            x[0][j - 1] = "#"
        elif (i == 0):
            x[1][j] = "#"
            x[0][j - 1] = "#"
            x[0][j + 1] = "#"
        elif (j == 0):
            x[i - 1][0] = "#"
            x[i + 1][0] = "#"
            x[i][1] = "#"
        elif (i == num_i - 1):
            x[i - 1][j] = "#"
            x[i][j + 1] = "#"
            x[i][j - 1] = "#"
        elif (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
        else:
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
            x[i][j + 1] = "#"
    if len(set(list(x.flatten()))) == 1:
        boolean = False
    else:
        boolean = True

print(str(count))

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
while True:
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='#':
                l += [i,j]
    if len(l)==h*w:
        break
    ans += 1
    for l_ in l:
        a[l_[0]-1] = a[l_[0]-1][:l_[1]]+'#'+a[l_[0]-1][l_[1]+1:]
        a[l_[0]] = a[l_[0]][:l_[1]-1]+'###'+a[l_[0]][l_[1]+2:]
        a[l_[0]+1] = a[l_[0]+1][:l_[1]]+'#'+a[l_[0]+1][l_[1]+1:]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import*


h, w = map(int, input().split())
A=[]

for i in range(0,h):
    A.append(list(str(x) for x in input()))
    
i=0

A = np.array(A)

B = np.where(A == "#")
B1 = np.array([B[0], B[1]]).T

B2 = []

for i in range(0,h):
    if A[i,0] == ".":
         B2.append([i,0])
    if A[i,w-1] == ".":
        B2.append([i,w-1])
    
for i in range(0,w):
    if A[0,i] == ".":
         B2.append([0,i])
    if A[h-1,i] == ".":
        B2.append([h-1,i])
    
C1=np.zeros(len(B1))
C2=np.zeros(len(B2))

for i in range(0,len(B1)):
    temp=[]
    for j in range(0,i):
        temp.append(math.ceil(sum(np.abs(B1[i]-B1[j]))/2))
        C1[i]=min(temp)
        
for i in range(0, len(B2)):
    temp=[]
    for j in range(0,len(B1)):
        temp.append(sum(np.abs(B2[i]-B1[j])))
        C2[i]=min(temp)

C3= np.insert(C1,0,C2)
print(int(max(C3)))

Submission status: Runtime Error

Solution code:
import sys

H, W = input().split()
H = int(H)
W = int(W)
A = []
for h in range(H):
    A.append(input())
A = ''.join(A)

count = 0

while True:
    A = list(A)
    indexes = [i for i, x in enumerate(A) if x == '#']

    for a in indexes:
        if a < W and A[a + W] = '.':
            A[a + W] = '#'
        elif a > (H*W)-W-1 and A[a - W] = '.':
            A[a - W] = '#'
        elif A[a + W] = '.' and A[a - W] = '.':
            A[a + W] = '#'
            A[a - W] = '#'

        if a%W == 0 and A[a + 1] = '.':
            A[a + 1] = '#'
        elif a%W == W-1 and A[a - 1] = '.':
            A[a - 1] = '#'
        elif A[a + 1] = '.' and A[a - 1] = '.':
            A[a + 1] = '#'
            A[a - 1] = '#'
        A[a] = '0'

    count = count + 1
    A = ''.join(A)

    b = A.find('.')
    if b < 0:
        print(count)
        sys.exit()

Submission status: Runtime Error

Solution code:
import numpy as np
import math

h, w = map(int, input().split())
A=[]

for i in range(0,h):
    A.append(list(str(x) for x in input()))
    
i=0

A = np.array(A)

B = np.where(A == "#")
B1 = np.array([B[0], B[1]]).T

B2 = []

for i in range(0,h):
    if A[i,0] == ".":
         B2.append([i,0])
    if A[i,w-1] == ".":
        B2.append([i,w-1])
    
for i in range(0,w):
    if A[0,i] == ".":
         B2.append([0,i])
    if A[h-1,i] == ".":
        B2.append([h-1,i])
    
C1=np.zeros(len(B1))
C2=np.zeros(len(B2))

for i in range(0,len(B1)):
    temp=[]
    for j in range(0,i):
        temp.append(math.ceil(sum(np.abs(B1[i]-B1[j]))/2))
        C1[i]=min(temp)
        
for i in range(0, len(B2)):
    temp=[]
    for j in range(0,len(B1)):
        temp.append(sum(np.abs(B2[i]-B1[j])))
        C2[i]=min(temp)

C3= np.insert(C1,0,C2)
print(int(max(C3)))

Submission status: Runtime Error

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline
[row, col] = list(map(int, input().split()))

mas=[]

mas = [list(input()) for l in range(row)]

print()
# print(row, col)
for i in range(row):
    print(mas[i])
    
print()

flag = True
count = 0

while(flag):
    flag = False
    for i in range(row):
        if ('.' in mas[i]):
            flag = True
    
    if flag == False:
        break
    
    mas2 = copy.deepcopy(mas)
    for i in range(row):
        for j in range(col):
            # print(mas[i][j])
            if mas[i][j] == '#':
                #print(i, j)
                if (i-1) >= 0:
                    mas2[i-1][j] = '#'
            
                if (i + 1) <= (row-1):
                    mas2[i+1][j] = '#'

                if (j-1) >= 0:
                    mas2[i][j-1] = '#'
            
                if (j + 1) <= (col-1):
                    mas2[i][j+1] = '#'

                    

        
    mas = copy.deepcopy(mas2)
    print()
    for i in range(row):
        print(mas[i])    
    print()
    
    count+=1
    
print(count)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(H: int, W: int, A: "List[str]"):
    queue = deque()

    for i,l in enumerate(A):
        for j, c in enumerate(l):
            if c == '#':
                queue.append((i, j, 0))
    
    ret = 0
    visited = [[False] * W for _ in range(H)]
    while queue:
        i, j, n = queue.popleft()
        if visited[i][j]:
            continue
        visited[i][j] = True

        ret = max(ret, n)
        if 0 < j:
            queue.append((i, j - 1, n + 1))
        if j < W - 1:
            queue.append((i, j + 1, n + 1))
        if 0 < i:
            queue.append((i - 1, j, n + 1))
        if i < H - 1:
            queue.append((i + 1, j, n + 1))
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    result = solve(H, W, A)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from queue import Queue

def inside(x, l, r):
    return l <= x < r

if __name__ == '__main__':
    h, w = map(int, input().split())

    a = [input() for _ in range(h)]

    qu = Queue()

    nokori = h*w
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                nokori -= 1
                qu.put(i*w + j)

    ans = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    while nokori:
        ans += 1
        qu2 = Queue()
        while not qu.empty():
            i0, j0 = divmod(qu.get(), w)
            for k in range(4):
                ni = i0 + dx[k]
                nj = j0 + dy[k]
                if not (inside(ni, 0, h) and inside(nj, 0, w)):
                    continue
                if a[ni][nj] == '.':
                    a[ni][nj] = '#'
                    nokori -= 1
                    qu2.put(ni*w+nj)
        qu = qu2
    print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
li=[input() for i in range(h)]





black=list()
bli=[[0 for j in range(h)] for i in range(w)]
count=0

for i in range(h):
    for j  in range(w):
        if li[i][j]=="#":
            black.append([i,j])
            bli[i][j]=1

def check(li):
    s=0
    for i in li:
        for j in i:
            if j==0:
                return True
            
    return False
        
        
while check(bli):
    tmp=[]
    for i in black:
        try:
            bli[i[0]-1][i[1]]=1
            tmp.append([i[0]-1,i[1]])
        except:
            pass
        try:
            bli[i[0]+1][i[1]]=1
            tmp.append([i[0]+1,i[1]])
        except:
            pass
        try:
            bli[i[0]][i[1]+1]=1
            tmp.append([i[0],i[1]+1])
        except:
            pass
        try:
            bli[i[0]][i[1]-1]=1
            tmp.append([i[0],i[1]-1])
        except:
            pass
    black=tmp[:]
    count+=1
    
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

ij = list(map(int, input().split()))
num = 0
cor_n = np.zeros((ij[1],ij[0]), dtype = 'int8')
for y in range(ij[0]):
    index = [u for u, v in enumerate(str(input())) if v == '#']
    if index != []:
        for x in index:
            cor_n[y, x] = 1
cnt=0

while(np.any(cor_n == 0) ):
    for u in list(zip(np.where(cor_n == 1)[0], np.where(cor_n == 1)[1])):
        if (u[0] - 1 >= 0):
            cor_n[u[0]-1, u[1]] = 1
        if (u[0] + 1 < ij[1]):
            cor_n[u[0]+1, u[1]] = 1
        if (u[1] + 1 < ij[0]):
            cor_n[u[0], u[1]+1] = 1
        if (u[1] - 1 >= 0):
            cor_n[u[0], u[1]-1] = 1
    cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy import ndimage

H, W = map(int, input().split())

A_array = np.array(
    [[0 if s == "#" else 1 for s in input()[:-1]] for i in range(H)])


b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(H: int, W: int, A: "List[str]"):
    queue = deque()

    for i,l in enumerate(A):
        for j, c in enumerate(l):
            if c == '#':
                queue.append((i, j, 0))
    
    ret = 0
    visited = [[False] * W for _ in range(H)]
    while queue:
        i, j, n = queue.popleft()
        if visited[i][j]:
            continue
        visited[i][j] = True

        ret = max(ret, n)
        if 0 < j:
            queue.append((i, j - 1, n + 1))
        if j < H - 1:
            queue.append((i, j + 1, n + 1))
        if 0 < i:
            queue.append((i - 1, j, n + 1))
        if i < W - 1:
            queue.append((i + 1, j, n + 1))
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    result = solve(H, W, A)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

num_i, num_j = map(int, input().split())
inputs = [input() for i in range(num_i)]

x = []
for _ in inputs:
    for value in _:
        x.append(value)
x = np.array(x)
x = x.reshape(num_i, num_j)

count = 0
boolean = True
while (boolean):
    count += 1
    i_arr = []
    j_arr = []
    for i in range(num_i):
        for j in range(num_j):
            if (x[i][j] == "#"):
                i_arr.append(i)
                j_arr.append(j)
    for i, j in zip(i_arr, j_arr):
        if (i == 0) & (j == 0):
            x[1][0] = "#"
            x[0][1] = "#"
        elif (i == num_i - 1) & (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i][j - 1] = "#"
        elif (i == num_i - 1) & (j == 0):
            x[i - 1][0] = "#"
            x[i][1] = "#"
        elif (i == 0) & (j == num_j - 1):
            x[1][j] = "#"
            x[0][j - 1] = "#"
        elif (i == 0):
            x[1][j] = "#"
            x[0][j - 1] = "#"
            x[0][j + 1] = "#"
        elif (j == 0):
            x[i - 1][0] = "#"
            x[i + 1][0] = "#"
            x[i][1] = "#"
        elif (i == num_i - 1):
            x[i - 1][j] = "#"
            x[i][j + 1] = "#"
            x[i][j - 1] = "#"
        elif (j == num_j - 1):
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
        else:
            x[i - 1][j] = "#"
            x[i + 1][j] = "#"
            x[i][j - 1] = "#"
            x[i][j + 1] = "#"
    if len(set(list(x.flatten()))) == 1:
        print(str(count))
        boolean = False
    else:
        boolean = True

Submission status: Runtime Error

Solution code:
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    line = input()
    ary.append(line)


from copy import deepcopy


def update(ary):
    tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] == 0:
                if x > 0:
                    tmp[y][x-1] = min(ary[y][x-1], 0)
                if x < w-1:
                    tmp[y][x+1] = min(ary[y][x+1], 0)
                if y > 0:
                    tmp[y-1][x] = min(ary[y-1][x], 0)
                if y < h-1:
                    tmp[y+1][x] = min(ary[y+1][x], 0)
                tmp[y][x] = -1
    return tmp


def init_ary(ary):
    # #. -> 0, 1, 2
    tmp = [[] for i in range(w)]
    for y in range(h):
        for x in range(w):
            tmp[y].append(1 if ary[y][x] == '.' else 0)
    return tmp


def is_all_black(ary):
    return not any(1 in line for line in ary)

ary = init_ary(ary)

count = 0

while not is_all_black(ary):
    ary = update(ary)
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
listA=[]
list01 = [[h+w] * h for i in range(w)]
for i in range(h):
    eline=input()
    listA.append(eline)

loclist=[]
n1=0
for i in range(h):
    for j in range(w):
        if listA[i][j]=='#':
            list01[i][j]=0
            loclist.append((i,j))
            n1=n1+1

for pt in loclist:
    
    for i in range(-1,2):
        for j in range(-1,2):
            if abs(i)+abs(j)==1:
                x=pt[0]+i
                y=pt[1]+j            
                if -1<x<h and -1<y<w:
                    loclist.append((x,y))
                    if list01[x][y]==(h+w):
                        n1=n1+1
                    if list01[x][y]>list01[pt[0]][pt[1]]+1:
                        list01[x][y]=list01[pt[0]][pt[1]]+1
                        
        if n1==h*w:
            break
mx=0
for i in range(h):
    for j in range(w):
        if list01[i][j]>mx:
            mx=list01[i][j]
print(mx)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[0 if c == '.' else 1 for c in input().strip()] for _ in range(H)]

    A = np.array(A)
    B = np.array(np.nonzero(A))
    Bx = np.tile(B[0], (H*W,1))
    By = np.tile(B[1], (H*W,1))

    _, n = B.shape
    x = list(range(H)) * W
    x.sort()
    X = np.array([x]*n)

    y = list(range(W)) * H
    Y = np.array([y]*n)

    d = np.abs(X - Bx.T) + np.abs(Y - By.T)
    return np.max(np.min(d, axis=0))

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa.pop(i)
        if not c == 0:
            if aa[c-1][v] > aa[c][v]+1:
                aa[c-1][v] = aa[c][v]+1
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] > aa[c][v]+1:
                aa[c+1][v] = aa[c][v]+1
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] > aa[c][v]+1:
                aa[c][v-1] = aa[c][v]+1
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] > aa[c][v]+1:
                aa[c][v+1] = aa[c][v]+1
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)

Submission status: Runtime Error

Solution code:
import numpy as np
 
ij = list(map(int, input().split()))
cor = []
num = 0
for y in range(ij[0]):
    index = [u for u, v in enumerate(str(input())) if v == '#']
    if index != []: 
        for x in index:
            cor.append([y, x])
    num = len(index) + num
cor_n = np.zeros((ij[1],ij[0]), dtype = 'int8')
cnt=0
 
if num == 1:
    max_x = max(ij[0] - (cor[0][0]+1), cor[0][0])
    max_y = max(ij[1] - (cor[0][1]+1), cor[0][1])
    print(max_x+max_y)
elif num > 1:
    for u in cor:
        cor_n[u[0],u[1]]=1
    while(np.any(cor_n == 0) ):
        for u in list(zip(np.where(cor_n == 1)[0], np.where(cor_n == 1)[1])):
            if (u[0] - 1 >= 0):
                cor_n[u[0]-1, u[1]] = 1
            if (u[0] + 1 < ij[1]):
                cor_n[u[0]+1, u[1]] = 1
            if (u[1] + 1 < ij[0]):
                cor_n[u[0], u[1]+1] = 1
            if (u[1] - 1 >= 0):
                cor_n[u[0], u[1]-1] = 1
        cnt+=1
    print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
 
ij = list(map(int, input().split()))
cor = []
num = 0
for y in range(ij[0]):
    index = [u for u, v in enumerate(str(input())) if v == '#']
    if index != []: 
        for x in index:
            cor.append([y, x])
    num = len(index) + num
cor_n = np.zeros((ij[1],ij[0]), dtype = 'int8')
cnt=0
 
if num == 1:
    max_x = max(ij[0] - (cor[0][0]+1), cor[0][0])
    max_y = max(ij[1] - (cor[0][1]+1), cor[0][1])
    print(max_x+max_y)
elif num > 1:
    for u in cor:
        cor_n[u[0],u[1]]=1
    while(np.any(cor_n == 0) ):
        for u in list(zip(np.where(cor_n == 1)[0], np.where(cor_n == 1)[1])):
            print(u, u[0],u[1])
            if (u[0] - 1 >= 0):
                cor_n[u[0]-1, u[1]] = 1
            if (u[0] + 1 < ij[1]):
                cor_n[u[0]+1, u[1]] = 1
            if (u[1] + 1 < ij[0]):
                cor_n[u[0], u[1]+1] = 1
            if (u[1] - 1 >= 0):
                cor_n[u[0], u[1]-1] = 1
        cnt+=1
    print(cnt)

Submission status: Runtime Error

Solution code:
# coding:utf-8
Black = "#"
White = "."

dir_x = [1, 0, -1, 0]
dir_y = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    memo = [[-1]*W for i in range(H)]
    step = 0
    masu = []
    for i in range(H):
        temp = input()
        for c in temp:
            if masu[y][x] == Black:
                memo[y][x] = 0
                steplist.append([y, x])

    while len(steplist) > 0:
        temp_step = step
        step += 1
        next_list = []
        for l in steplist:
            y = l[0]
            x = l[1]
            for i in range(4):
                temp_x = x + dir_x[i]
                temp_y = y + dir_y[i]
                if temp_x >= 0 and temp_x < W and temp_y >= 0 and temp_y < H and memo[temp_y][temp_x] < 0:
                    memo[temp_y][temp_x] = step
                    next_list.append([temp_y, temp_x])
        steplist = next_list
    print(step)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import os
import copy
from math import *

nums = []
for i in list(input().split()):
  nums.append(int(i))

#print(nums)

fields = []
for i in range(nums[0]):
	n = []
	words = list(input())
	for j in range(nums[1]):
		if words[j] == '#':
			n.append(3)
		else:
			n.append(0)
	fields.append(n)

#print(fields)

for i in range(nums[0]):
		for j in range(nums[1]):
			check_list = [i, j]

count = 3
# -*- coding: utf-8 -*-
import sys
import os
import copy
from math import *

nums = []
for i in list(input().split()):
  nums.append(int(i))

#print(nums)

fields = []
for i in range(nums[0]):
	n = []
	words = list(input())
	for j in range(nums[1]):
		if words[j] == '#':
			n.append(3)
		else:
			n.append(0)
	fields.append(n)

#print(fields)

check_list = []
for i in range(nums[0]):
		for j in range(nums[1]):
			check_list.append([i, j])

count = 3
while True:
	check_list_next = []

	for mass in check_list:
		i = mass[0]
		j = mass[1]
		
		if fields[i][j] == count:
			if 0 < i:
				if fields[i-1][j] == 0:
					fields[i-1][j] = count + 1
					check_list_next.append([i-1, j])

			if i < nums[0]-1:
				if fields[i+1][j] == 0:
					fields[i+1][j] = count + 1
					check_list_next.append([i+1, j])

			if 0 < j:
				if fields[i][j-1] == 0:
					fields[i][j-1] = count + 1
					check_list_next.append([i, j-1])

			if j < nums[1]-1:
				if fields[i][j+1] == 0:
					fields[i][j+1] = count + 1
					check_list_next.append([i, j+1])

	check_list = check_list_next

	#for i in range(nums[0]):
	#	print(fields[i])
	#print("")

	#print(check_list)

	if len(check_list):
		count = count + 1
	else:
		break

print(count-3)
	changed = 0
	for i in range(nums[0]):
		for j in range(nums[1]):
			if fields[i][j] == count:
				if 0 < i:
					if fields[i-1][j] == 0:
						fields[i-1][j] = count + 1
						changed = 1

				if i < nums[0]-1:
					if fields[i+1][j] == 0:
						fields[i+1][j] = count + 1
						changed = 1

				if 0 < j:
					if fields[i][j-1] == 0:
						fields[i][j-1] = count + 1
						changed = 1

				if j < nums[1]-1:
					if fields[i][j+1] == 0:
						fields[i][j+1] = count + 1
						changed = 1

	#for i in range(nums[0]):
	#	print(fields[i])
	#print("")

	if changed:
		count = count + 1
	else:
		break

print(count-3)

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa.pop(0)
        if not c == 0:
            if aa[c-1][v] != min(aa[c][v]+1,aa[c-1][v]):
                aa[c-1][v] = min(aa[c][v]+1,aa[c-1][v])
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] != min(aa[c][v]+1,aa[c+1][v]):
                aa[c+1][v] = min(aa[c][v]+1,aa[c+1][v])
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] != min(aa[c][v]+1,aa[c][v-1]):
                aa[c][v-1] = min(aa[c][v]+1,aa[c][v-1])
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] != min(aa[c][v]+1,aa[c][v+1]):
                aa[c][v+1] = min(aa[c][v]+1,aa[c][v+1])
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)

Submission status: Runtime Error

Solution code:
h,w=input().split()
H = int(h)
W = int(w)
A = list()
A_ = list()
for i in range(H):
    A.append([""]*W)
    A_.append([""]*W)
    x = input()
    for j in range(W):
        for k in range(W):
            A[i][k] = x[k]
            A_[i][k] = x[k]
go = True

#黒「#」 白「.」
#「.」を「＃」にする
#ひっくり返し関数
def reverse(A,Pre):
    #Aリバースあと
    #Bリバース前
    for i in range(H):
        for j in range(W):
            if Pre[i][j] == "#":
                if i == 0:
                    if j == 0:
                        A[0][1] = "#"
                        A[1][0] = "#"
                    elif j == W-1:
                        A[0][W-2] = "#"
                        A[1][W-1] = "#"
                    else:
                        A[i][j-1] = "#"
                        A[i][j+1] = "#"
                        A[i+1][j] = "#"
                
                elif i == H-1:
                    if j == 0:
                        A[H-1][1] = "#"
                        A[H-1-1][0] = "#"
                    elif j == W-1:
                        A[H-1-1][W-1] = "#"
                        A[H-1][W-2] = "#"
                    else:
                        A[H-1][j-1] = "#"
                        A[H-1][j+1] = "#"
                        A[H-1-1][j] = "#"
                
                elif i != 0 and i != H-1:
                    if j == 0:
                        A[i][0+1] = "#"
                        A[i-1][0] = "#"
                        A[i+1][0] = "#"
                    elif j == W-1:
                        A[i][W-1-1] = "#"
                        A[i-1][W-1] = "#"
                        A[i+1][W-1] = "#"
                    else:
                        A[i-1][j] = "#"
                        A[i][j-1] = "#"
                        A[i][j+1] = "#"
                        A[i+1][j] = "#"

#全部黒か判定関数
def judge(A):
    global n
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                n += 1
            else:
                pass
    n == H*W

#本体プログラム
from copy import deepcopy
ans = 0
n = 0
while n != H*W:
    n = 0
    ans += 1
    reverse(A_,A)
    #Pre == A
    A = deepcopy(A_)
    judge(A)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

h, w = map(int, input().split())
A=[]

for i in range(0,h):
    A.append(list(str(x) for x in input()))
    
i=0

A = np.array(A)

B = np.where(A == "#")
B1 = np.array([B[0], B[1]]).T

B2 = []

for i in range(0,max(h,w)):
    if (i<h) & (A[i,0] == "."):
         B2.append([i,0])
    if (i<h) & (A[i,w-1] == "."):
        B2.append([i,w-1])
    if (i<w) & (A[0,i] == "."):
         B2.append([0,i])
    if (i<w) & (A[h-1,i] == "."):
        B2.append([h-1,i])
    
C1=np.zeros(len(B1))
C2=np.zeros(len(B2))

for i in range(0,len(B1)):
    temp=[]
    for j in range(0,i):
        temp.append(math.ceil(sum(np.abs(B1[i]-B1[j]))/2))
        C1[i]=min(temp)
        
for i in range(0, len(B2)):
    temp=[]
    for j in range(0,len(B1)):
        temp.append(sum(np.abs(B2[i]-B1[j])))
        C2[i]=min(temp)

C3= np.insert(C1,0,C2)
print(int(max(C3)))

Submission status: Runtime Error

Solution code:
import numpy as np

ij = list(map(int, input().split()))
cor = []
num = 0
for y in range(ij[0]):
    index = [u for u, v in enumerate(str(input())) if v == '#']
    if index != []: 
        for x in index:
            cor.append([y, x])
    num = len(index) + num
cor_n = np.zeros((ij[1],ij[0]), dtype = 'int8')
cnt=0

if num == 1:
    max_x = max(ij[0] - (cor[0][0]+1), cor[0][0])
    max_y = max(ij[1] - (cor[0][1]+1), cor[0][1])
    print(max_x+max_y)
elif num > 1:
    for u in cor:
        cor_n[u[0],u[1]]=1
    print(cor_n)
    print(np.any(cor_n == 0))
    while(np.any(cor_n == 0) ):
        for u in list(zip(np.where(cor_n == 1)[0], np.where(cor_n == 1)[1])):
            print(u, u[0],u[1])
            if (u[0] - 1 >= 0):
                cor_n[u[0]-1, u[1]] = 1
            if (u[0] + 1 < ij[1]):
                cor_n[u[0]+1, u[1]] = 1
            if (u[1] + 1 < ij[0]):
                cor_n[u[0], u[1]+1] = 1
            if (u[1] - 1 >= 0):
                cor_n[u[0], u[1]-1] = 1
        cnt+=1
    print(cnt)