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:
import copy

h, w = map(int, input().split())

arr = []
for ih in range(h):
  tmp_arr = []
  x = str(input())
  for iw in range(w):
    tmp_arr.append(x[iw])
  arr.append(tmp_arr)

             
arr_next = copy.deepcopy(arr)
cnt = 0
flg = 0

while flg == 0:
  cnt = cnt + 1
  flg = 1

  for ih in range(h):
    if '.' in arr_next[ih]:
      for iw in range(w):
        if (ih - 1 >= 0 and arr[ih - 1][iw] == '#') + (ih + 1 < h and arr[ih + 1][iw] == '#') + (iw - 1 >= 0 and arr[ih][iw - 1] == '#') + (iw + 1 < w and arr[ih][iw + 1] == '#') > 0:
          arr_next[ih][iw] = '#'
  for ih in range(h):
    if '.' in arr_next[ih]:
      flg = 0
      break
  arr = copy.deepcopy(arr_next)
  
print(cnt)

Submission status: Wrong Answer

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


black_list = []
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            black_list.append([i, j])

counter = 0
while True:
    counter += 1
    new = []
    for black in black_list:
        for (i, j) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nh = black[0] + i
            nw = black[1] + j
            if 0 <= nh and nh < h and 0 <= nw and nw < w and s[nh][nw] == '.' and [nh, nw] not in new:
                new.append([nh, nw])
                s[nh][nw] = '#'

    black_list.extend(new)
    if len(black_list) == h * w:
        break
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = []

for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        t.append([i,j])

p = 10 **18
q = 0
m = h  // 4
n = w // 4
for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        continue
                else:
                        p = 10 **18
                        for k in range(len(t)):
                                if (t[k][0] < i - m or t[k][0] > i+m) or (t[k][1] < j- n or t[k][1] > i + n):
                                        continue
                                elif p > abs(i-t[k][0]) + abs(j-t[k][1]):
                                        p = abs(i-t[k][0]) + abs(j-t[k][1])
                        if q < p:
                                q = p
print(q)

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split(" ")))
A = []

def check(A, i, j, H, W):
    if i < H-1:
        if A[i+1][j] == '#':
            return 1
    if i > 0:
        if A[i-1][j] == '#':
            return 1
    if j < W-1:
        if A[i][j+1] == '#':
            return 1
    if j > 0:
        if A[i][j-1] == '#':
            return 1
    return 0

for i in range(H):
    A.append(list(input()))
    
cnt = 1
for _ in range(100):
    lis = []
    for i in range(H):
        for j in range(W):
            if A[i][j] == '.':
                if check(A, i, j, H, W):
                    lis.append([i,j])
    for i,j in lis:
      A[i][j] = '#'
   	
    X = []
    for x in A:
        X.extend(x)
    if '.' in X:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
def is_(i,j,X,A):
    up = max(0, i-1)
    down = min(i+1, X[0]-1)
    left = max(0, j-1)
    right = min(j+1, X[1]-1)
    res = A[i][j]+A[up][j]+A[down][j]+A[i][right]+A[i][left]
    return res > 0
    
X = [int(i) for i in input().split()]
A = [[s=="#" for s in input()] for _ in range(X[0])]
for n in range(1,1000000):
    A = [[is_(i,j,X,A) for j in range(X[1])] for i in range(X[0])]
    if sum([sum(a) for a in A])==X[0]*X[1]:
        break
print(n)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

H, W = [int(x) for x in stdin.readline().rstrip().split()]

data = [list(stdin.readline().rstrip()) for _ in range(H)]

counter = 0


def allCellsAreBlack(arr):
    for i in range(H):
        if '.' in data[i]:
            return False
    return True


def checkBlackCellnearby(h, w):
    if h != 0:
        if data[h - 1][w] == '#':
            return True
    if h != H-1:
        if data[h + 1][w] == '#':
            return True
    if w != 0:
        if data[h][w - 1] == '#':
            return True
    if w != W-1:
        if data[h][w + 1] == '#':
            return True
    else:
        return False


def enBlack(pos):
    i, j = pos
    # if i != 0 and (data[i - 1][j] == '#'):
    #     data[i][j] = '#'
    # elif i != H - 1 and (data[i + 1][j] == '#'):
    #     data[i][j] = '#'
    # elif j != 0 and (data[i][j - 1] == '#'):
    #     data[i][j] = '#'
    # elif j != W - 1 and (data[i][j + 1] == '#'):
    #     data[i][j] = '#'
    data[i][j] = '#'


whiteList = []

while(True):
    for h in range(H):
        for w in range(W):
            if data[h][w] == '.' and checkBlackCellnearby(h, w):
                whiteList.append((h, w))

    for pos in whiteList:
        enBlack(pos)

    whiteList = []

    counter += 1
    if allCellsAreBlack(data):
        print(counter)
        sys.exit()

Submission status: Wrong Answer

Solution code:
number = input().split()

number1 = int(number[0])
number2 = int(number[1])

for i in range(number1):
    block = input()

print(2)

Submission status: Wrong Answer

Solution code:
first_input = list(map(int, input().split()))
height = first_input[0]
width = first_input[1]

area = []
for i in range(0, height):
  line = input()
  for k in range(0, width):
    area.append(line[k:k+1])

area_length = len(area)
answer = 0

while(True):
  answer += 1
  target_indices = []
  for i,item in enumerate(area):
    if item == '#':
      target_indices.append(i)
  for target_index in target_indices:
    # 左方向
    if target_index - 1 >= 0 and target_index % width != 0:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length and target_index % width != width-1:
    	area[target_index + 1] = '#'
    # 下方向
    if target_index + width < area_length:
    	area[target_index + width] = '#'
    # 上方向
    if target_index - width >= 0:
    	area[target_index - width] = '#'
  target_indices = []
  if '.' not in area:
    break

print(answer)

Submission status: Wrong Answer

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

non=3000
import numpy as np
b=np.ones((h,w),dtype=int)*non

ans=0

u=np.ones((h,w),dtype=int)*non
for i in range(h):
    l=np.ones(w,dtype=int)*non
    for j in range(w):
        if a[i][j]=='#':
            l[j]=0
        elif j>0 and l[j-1]!=non:
            l[j]=l[j-1]+1
    r=non
    for j in range(w-1,-1,-1):
        if a[i][j]=='#':
            b[i][j]=0
            r=0
        elif j<w-1 and r!=non:
            r+=1
        b[i][j]=min(l[j],r)
    if i>0:
        u[i]=np.min((b[i],b[i-1]+1),axis=0)
d=np.ones(w,dtype=int)*non
for i in range(h-1,-1,-1):
    if i<h-1:
        d=np.min((b[i],b[i+1]+1),axis=0)
    b[i]=np.min((u[i],d),axis=0)
    ans=max(ans,np.max(b[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
first_input = list(map(int, input().split()))
height = first_input[0]
width = first_input[1]

area = []
for i in range(0, height):
  line = input()
  for k in range(0, width):
    area.append(line[k:k+1])

area_length = len(area)
answer = 0

while(True):
  answer += 1
  target_indices = []
  for i,item in enumerate(area):
    if item == '#':
      target_indices.append(i)
  for target_index in target_indices:
    # 左方向
    if target_index - 1 >= 0 and target_index % width != 0:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length and target_index % width != width-1:
    	area[target_index + 1] = '#'
    # 下方向
    if target_index + width < area_length:
    	area[target_index + width] = '#'
    # 上方向
    if target_index - width >= 0:
    	area[target_index - width] = '#'
  target_indices = []
  if '.' not in area:
    break

print(answer)

Submission status: Wrong Answer

Solution code:
from io import StringIO
from collections import deque
import sys


def main(inputs):
    h, w = map(int, next(inputs).split())
    mass = [ next(inputs) for _ in range(h) ]
    
    ans = [[-1 for _ in m] for m in mass]
    
    for i in range(h):
        for j in range(w):
            if ans[i][j] == -1:
                find_black(mass, ans, i, j)
                pass
            pass
        pass
    print(ans)
    print(max([ max(a) for a in ans]))
    pass


def find_black(mass, ans, h, w):
    done = [[False for _ in m] for m in mass]
    q = deque()
    q.append((h, w, []))
    candidate = (-1, 0, [])
    candidate_ans = lambda: ans[candidate[0]][candidate[1]] + len(candidate[2])
    candidate_exists = lambda: (candidate[0] != -1)
    while q:
        h, w, path = q.popleft()
        if mass[h][w] == '#':
            ans[h][w] = 0
            for idx, (i, j) in enumerate(reversed(path)):
                ans[i][j] = idx + 1
                pass
            pass
        if ans[h][w] != -1:
            s0 = ans[h][w] + len(path)
            s1 = candidate_ans()
            if (not candidate_exists()) or s0 < s1:
                candidate = (h, w, path[:])
                pass
            done[h][w] = True
            continue
        if candidate_exists():
            if candidate_ans() <= len(path):
                h, w, path = candidate
                for idx, (i, j) in enumerate(reversed(path)):
                    ans[i][j] = ans[h][w] + idx + 1
                    pass
                return
            pass
        done[h][w] = True
        path.append((h, w))
        if h-1 >= 0 and not done[h-1][w]:
            q.append((h-1, w, path[:]))
            pass
        if h+1 < len(mass) and not done[h+1][w]:
            q.append((h+1, w, path[:]))
            pass
        if w-1 >= 0 and not done[h][w-1]:
            q.append((h, w-1, path[:]))
            pass
        if w+1 < len(mass[0]) and not done[h][w+1]:
            q.append((h, w+1, path[:]))
            pass
        pass
    pass

def gen_inputs(str_=None):
    inputs = StringIO(str_) if str_ else sys.stdin
    while True:
        a = inputs.readline().rstrip()
        yield a
        pass
    pass


if __name__ == "__main__":
    main(gen_inputs())
    pass

Submission status: Wrong Answer

Solution code:
import random
if random.random()>0.5:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

non=3000
import numpy as np
b=np.ones((h,w),dtype=int)*non

ans=0

u=np.ones((h,w))*non
for i in range(h):
    l=np.ones(w,dtype=int)*non
    for j in range(w):
        if a[i][j]=='#':
            l[j]=0
        elif j>0 and l[j-1]!=non:
            l[j]=l[j-1]+1
    r=non
    for j in range(w-1,-1,-1):
        if a[i][j]=='#':
            b[i][j]=0
            r=0
        elif j<w-1 and r!=non:
            r+=1
        b[i][j]=min(l[j],r)
    if i>0:
        u[i]=np.min((b[i],b[i-1]+1),axis=0)
d=np.ones(w,dtype=int)*non
for i in range(h-1,-1,-1):
    if i<h-1:
        d=np.min((b[i],b[i+1]+1),axis=0)
    b[i]=np.min((u[i],d),axis=0)
    ans=max(ans,np.max(b[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
alist = [list(".{}.".format(input())) for j in range(H)]

s = ['.' for i in range(W + 2)]
alist.insert(0, s)
alist.append(s)

alist = [[(1 if i == '#' else 0) for i in j] for j in alist]

import copy
adumy = copy.deepcopy(alist)

is_proc = True
c = 0
lm = lambda x, y: alist[x][y] + max(alist[x][y-1], alist[x-1][y], alist[x+1][y], alist[x][y+1])
while is_proc:
  is_proc = False
  
  for i in range(1, H+1):
    for j in range(1, W+1):
      adumy[i][j] = lm(i, j)
  #adumy = [[lm(i, j) for j in range(1, W+1)] for i in range(1, H+1)]
  
  for li_ in adumy[:][1:-1]:
    if 0 in li_[1:-1]:
      is_proc = True
  
  alist = copy.deepcopy(adumy)
  #[print(j) for j in adumy]
  #print()
  
  c += 1

print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = []

for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        t.append([i,j])

p = 10 **18
q = 0
for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        continue
                else:
                        p = 10 **18
                        for k in range(len(t)):
                                if p > abs(i-t[k][0]) + abs(j-t[k][1]):
                                        p = abs(i-t[k][0]) + abs(j-t[k][1])
                                        c = 0
                                else:
                                        c += 1
                                if c > 20:
                                        break
                        if q < p:
                                q = p
print(q)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
H, W = map(int, input().split())
arr = [0]*H
for i in range(H):
    arr[i] = [j for j in input()]

a, b = np.where(np.array(arr)=='#')
abb = np.array([list(a), list(b)])
res = 0
x = np.array(range(H))
y = np.array(range(W))
xx, yy = np.meshgrid(x,y)
z = np.c_[xx.ravel(),yy.ravel()].reshape(2, -1)

for zz in abb.T:
  res1 = 3000
  res1 = min(np.amin(np.sum(abs(zz.reshape(2, -1) - z), axis=0)), res1)
  res = max(res1, res)
        
print(res)

Submission status: Wrong Answer

Solution code:
a=input()
H=int(a.split()[0])
W=int(a.split()[1])
A=[]
for i in range(H):
  a=input()
  for j in range(W):
    A.append(a[j])
B=[]
count=0

while True:
  count+=1
  B.clear()
  for i,val in enumerate(A):
    if(val=="#"):
      B.append(i)
  for num in(B):
    if(num > W):
      A[num-W]="#"
    if(num % W != 0):
      A[num-1]="#"
    if(num % W != W-1):
      A[num+1]="#"
    if(num < H*W-W):
      A[num+W]="#"
  if(len(A)==A.count("#")):
    print(count)
    break

Submission status: Wrong Answer

Solution code:
li = input().split()
H=int(li[0])
W=int(li[1])
li =[]

for j in range(H):
  s=list(input())
  for i in range(W):
      if s[i]=="#" :
        li.append((i,j))

li.append((-1,-1))
li.append((-1,H))
li.append((W,-1))
li.append((W,H))

black=len(li)
max=0

for a in range(black):
  min = 2000
  for b in range(black):
    if a==b:
      continue
    k=abs(li[a][1]-li[b][1])+abs(li[a][0]-li[b][0])
    cand=k//2
    if cand < min:
      min = cand
  if min >= max:
    max=min

    

for i in range(W):
  min = 2000
  for l in range(black):
    k=abs(li[l][0]-i)+abs(li[l][1]-0)
    if k <= min:
      min = k
  if min >= max:
    max = min
    
for i in range(W):
  min = 2000
  for l in range(black):
    k=abs(li[l][0]-i)+abs(li[l][1]-H)
    if k <= min:
      min = k
  if min >= max:
    max = min

for i in range(H):
  min = 2000
  for l in range(black):
    k=abs(li[l][0]-0)+abs(li[l][1]-i)
    if k <= min:
      min = k
  if min >= max:
    max = min

for i in range(H):
  min = 2000
  for l in range(black):
    k=abs(li[l][0]-W)+abs(li[l][1]-i)
    if k <= min:
      min = k
  if min >= max:
    max = min
    
print(max)

Submission status: Wrong Answer

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

cnt = 0
while True:
    memory = []
    for i in range(w):
        for j in range(h):
            if masu[j][0][i] == '#':
                memory.append([i, j])
    if len(memory) == h * w:
        break
    for x, y in memory:
        try:
            # 左
            if masu[y][0][x - 1] == '.':
                masu[y][0] = masu[y][0][:x - 1] + '#' + masu[y][0][x:]
        except IndexError:
            pass
        try:
            # 右
            if masu[y][0][x + 1] == '.':
                masu[y][0] = masu[y][0][:x + 1] + '#' + masu[y][0][x + 2:]
        except IndexError:
            pass
        try:
            # 上
            if masu[y - 1][0][x] == '.':
                masu[y - 1][0] = masu[y - 1][0][:x] + '#' + masu[y - 1][0][x + 1:]
        except IndexError:
            pass
        try:
            # 下
            if masu[y + 1][0][x] == '.':
                masu[y + 1][0] = masu[y + 1][0][:x] + '#' + masu[y + 1][0][x + 1:]
        except IndexError:
            pass
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
hw = list(map(int, list(input().split())))
h = hw[0]
w = hw[1]

a = []
for i in range(h):
    apend = list(input())
    a.append(apend)

white = []

for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            white.append([i, j])

number1 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number1[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number1[i - 1][j]) + 1)
        else:
            number.append(0)
    number1.append(number)

print(number1)

number2 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number2[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number2[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    newnumber = []
    for k in number[::-1]:
        newnumber.append(k)
    number2.append(newnumber)

print(number2)


number3 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number3[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number3[i - 1][j]) + 1)
        else:
            number.append(0)
    number3.append(number)

number6 = number3
number3 = []
for i in number6[::-1]:
    number3.append(i)

print(number3)

number4 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number4[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number4[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    newnumber = []
    for k in number[::-1]:
        newnumber.append(k)
    number4.append(newnumber)

number6 = number4
number4 = []
for i in number6[::-1]:
    number4.append(i)

print(number4)

number5 = []

if len(white) == 0:
    print(0)
else:
    for i in range(len(white)):
        number5.append(min(number1[white[i][0]][white[i][1]], number2[white[i][0]][white[i][1]], number3[white[i][0]][white[i][1]], number4[white[i][0]][white[i][1]]))
    print(max(number5))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = []

for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        t.append([i,j])

p = 10 **18
q = 0
for i in range(h):
        for j in range(w):
                if s[i][j] == "#":
                        continue
                else:
                        p = 10 **18
                        for k in range(len(t)):
                                if p > abs(i-t[k][0]) + abs(j-t[k][1]):
                                        p = abs(i-t[k][0]) + abs(j-t[k][1])
                                        c = 0
                                else:
                                        c += 1
                                if c > 10:
                                        break
                        if q < p:
                                q = p
print(q)

Submission status: Wrong Answer

Solution code:
import copy
h, w = map(int, input().split())
a = [["."]*w]*h
for i in range(h):
    a[i] = list(input())
s=0
e=0
k=0
while s==0:
    b = copy.deepcopy(a)
    for i in range(h):
        for j in range(w):
            if b[i][j]=='#':
                for x in [-1,1,0]:
                    for y in [-1,1,0]:
                        if x!=y and x!=y*-1 and x+i >= 0 and x+i < h and y+j >= 0 and y+j < w:
                            if a[i+x][j+y] == '.':
                                a[i+x][j+y]='#'
    for i in range(h):
        for j in range(w):
            if a[i][j]=='.':
                e=1
                break
        if e==1:
            break
    if e==0:
        s=1
    k+=1
    e=0
print(k)

Submission status: Wrong Answer

Solution code:
from collections import deque

inf = float('inf')

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

e = [[inf for _ in range(W)] for _ in range(H)]


def next_pos(r, c):
    res = []
    for dr, dc in (-1, 0), (1, 0), (0, -1), (0, 1):
        nr = r + dr
        if not (0 <= nr < H): continue
        nc = c + dc
        if not (0 <= nc < W): continue
        if a[nr][nc] == '#': continue
        if e[nr][nc] < inf: continue
        res.append((nr, nc))
    return res


check_pos = deque()

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            check_pos += next_pos(r, c)

ans = 0
while True:
    # print(check_pos)
    ans += 1
    next_check_pos = []
    while check_pos:
        r, c = check_pos.popleft()
        e[r][c] = ans
        next_check_pos += next_pos(r, c)
    else:
        if not next_check_pos: break
        check_pos = deque()
        check_pos += next_check_pos

print(ans)

Submission status: Wrong Answer

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

non=3000
import numpy as np
b=np.ones((h,w),dtype=int)*non

ans=0

u=np.ones((h,w))*non
for i in range(h):
    l=[non]*w
    for j in range(w):
        if a[i][j]=='#':
            l[j]=0
        elif j>0 and l[j-1]!=non:
            l[j]=l[j-1]+1
    r=non
    for j in range(w-1,-1,-1):
        if a[i][j]=='#':
            b[i][j]=0
            r=0
        elif j<w-1 and r!=non:
            r+=1
        b[i][j]=min(l[j],r)
    if i>0:
        u[i]=np.min((b[i],b[i-1]+1),axis=0)
d=np.ones(w)*non
for i in range(h-1,-1,-1):
    if i<h-1:
        d=np.min((b[i],b[i+1]+1),axis=0)
    b[i]=np.min((u[i],d),axis=0)
    ans=max(ans,np.max(b[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
hw = list(map(int, list(input().split())))
h = hw[0]
w = hw[1]

a = []
for i in range(h):
    apend = list(input())
    a.append(apend)

white = []

for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            white.append([i, j])

number1 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(1)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number1[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number1[i - 1][j]) + 1)
        else:
            number.append(0)
    number1.append(number)

number2 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(1)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number2[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number2[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    newnumber = []
    for k in number[::-1]:
        newnumber.append(k)
    number2.append(newnumber)

#print(number2)


number3 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(1)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number3[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number3[i - 1][j]) + 1)
        else:
            number.append(0)
    number3.append(number)

number6 = number3
number3 = []
for i in number6[::-1]:
    number3.append(i)

number4 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(1)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number4[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number4[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    newnumber = []
    for k in number[::-1]:
        newnumber.append(k)
    number4.append(newnumber)

number6 = number4
number4 = []
for i in number6[::-1]:
    number4.append(i)

number5 = []

if len(white) == 0:
    print(0)
else:
    for i in range(len(white)):
        number5.append(min(number1[white[i][0]][white[i][1]], number2[white[i][0]][white[i][1]], number3[white[i][0]][white[i][1]], number4[white[i][0]][white[i][1]]))
    print(max(number5))

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))

M = {};

for i in range(H):
    M[i] = list(input())

#print(M)

count = 0

import copy

f = [[0 for _ in range(W) ] for _ in range(H) ]

temp = copy.deepcopy(M)

while True:
    count += 1

    for h in range(H):
        if M[h].count('#') == W:
            continue

        for w in range(W):
            if temp[h][w] == '#' and f[h][w] == 0:

                f[h][w] = 1

                for i in range(4):
                    if i == 0 and h != 0:
                        M[h - 1][w] = '#'

                    elif i == 1 and h != H - 1:
                        M[h + 1][w] = '#'

                    elif i == 2 and w != 0:
                        M[h][w - 1] = '#'

                    elif i == 3 and w != W - 1:
                        M[h][w + 1] = '#'

        temp[h] = M[h][:]

    # print(count)
    # for h in range(H):
    #     for w in range(W):
    #         print(M[h][w], end="")
    #     print()

    flg = False

    for h in range(H):
        flg = '.' in M[h]

        if flg:
            break

    if flg == False:
        print(count)
        exit(0)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
l = []
l2 = []
a = [input() for j in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            l.append((i,j))
        else:
            l2.append((i,j))
answer = 0
print("a")
while len(l2):
    b = []
    answer += 1
    for i, j in l2:
        for x, y in l:
            d = abs(i-x)+abs(j-y)
            if d == answer:
                b.append((i,j))
    b = set(b)
    for z in b:
        l2.remove(z)
                

print(answer)

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))

M = {};

for i in range(H):
    M[i] = list(input())

#print(M)

count = 0

import copy

f = [[0 for _ in range(W) ] for _ in range(H) ]

temp = copy.deepcopy(M)

while True:
    count += 1

    for h in range(H):
        if M[h].count('.') == 0:
            continue

        for w in range(W):
            if temp[h][w] == '#' and f[h][w] == 0:

                f[h][w] = 1

                for i in range(4):
                    if i == 0 and h != 0:
                        M[h - 1][w] = '#'

                    elif i == 1 and h != H - 1:
                        M[h + 1][w] = '#'

                    elif i == 2 and w != 0:
                        M[h][w - 1] = '#'

                    elif i == 3 and w != W - 1:
                        M[h][w + 1] = '#'

        temp[h] = M[h][:]

    # print(count)
    # for h in range(H):
    #     for w in range(W):
    #         print(M[h][w], end="")
    #     print()

    flg = False

    for h in range(H):
        flg = '.' in M[h]

        if flg:
            break

    if flg == False:
        print(count)
        exit(0)