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:
H,W = map(int, input().split())
A = []
for _ in range(H):
    A += [ [ 1 if x == "#" else 0 for x in input()] ]

import numpy as np


A = np.array(A)
WK = np.zeros(A.shape)
i = 0
S = H * W
while True:
    if np.min(A) == 1:
        break
    WK -= WK
    WK += A
    A[:-1] |= WK[1:]
    A[1:] |= WK[:-1]
    A[:,:-1] |= WK[:,1:]
    A[:,1:] |= WK[:,:-1]
    i += 1

print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
h, w = map(int, input().split())

M = h + w
data = np.ones((h+2, w+2), np.int16) * M
for ln in range(1, h+1):
    line = list(input().rstrip())
    for r, letter in zip(range(1, w+1), line):
        if letter == '#':
            data[ln,r] = 0

data = data.reshape((w,h))

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
m = ['X' + input() + 'X' for i in range(H)]
m.insert(0, 'X' * (W+2))
m.insert(H+1, 'X' * (W+2))
 
cnt = 0
while(True):
  flag = True
  mm = [['X' for i in range(W+2)] for j in range(H+2)]
  for i in range(1, 1+H):
    for j in range(1, 1+W):
      if m[i][j] == '.':
        if m[i+1][j] == '#' or m[i-1][j] == '#' or m[i][j+1] == '#' or m[i][j-1] == '#':
          mm[i][j] = '#'
        else:
          mm[i][j] = '.'
        if flag:
          flag = False
      elif m[i][j] == '#':
        mm[i][j] = '#'
  cnt += 1
  m = mm.copy()
  if flag:
    break
 
print(cnt-1)

Submission status: Runtime Error

Solution code:
def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]

    que = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append((h, w))

    if len(que) == H * W:
        print(0)
        exit()

    ans = 0
    while True:
        # print(A)
        # print(len(que))
        src = que.copy()
        que = []
        for s in src:
            h = s[0]
            w = s[1]
            dx4 = [0, 0, 1, -1]
            dy4 = [1, -1, 0, 0]
            for dx, dy in zip(dx4, dy4):
                nh = h + dy
                nw = w + dx

                if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':
                    que.append((nh, nw))
                    A[nh][nw] = '#'

        if len(que) == 0:
            break

        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# AtCoder Grand Contest 033
# https://atcoder.jp/contests/agc033
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import datetime

def main_ok():
    H, W = i2nn()
    HW = H * W
    A = ii2ss(H)
    A = [[0 if s == '#' else HW for s in line] for line in A]
    for i in range(H):
        for j in range(1, W):
            if A[i][j-1]+1 < A[i][j]:
                A[i][j] = A[i][j-1]+1
        for j in range(W-2, -1, -1):
            if A[i][j+1]+1 < A[i][j]:
                A[i][j] = A[i][j+1]+1
    for j in range(W):
        for i in range(1, H):
            if A[i-1][j]+1 < A[i][j]:
                A[i][j] = A[i-1][j]+1
        for i in range(H-2, -1, -1):
            if A[i+1][j]+1 < A[i][j]:
                A[i][j] = A[i+1][j]+1
    ans = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] > ans:
                ans = A[i][j]
    print(ans)

def check(i, j, q, count, H, W, A, rec):
    if A[i][j] == True:
        return count
    A[i][j] = True
    q.append((i, j))
    return count + 1
 
def main():
    H, W = i2nn()
    A = ii2ss(H)
    A = [[True] * (W+2)] + [[True] + [True if s == '#' else False for s in line] + [True] for line in A] + [['#'] * (W+2)]
    HW = H * W
    q = []
    count = 0
    rec = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if A[i][j] == True:
                q.append((i, j))
                count += 1
    while True:
        if count >= HW or len(q) == 0:
            print(rec)
            return
        rec += 1
        q2 = []
        for i, j in q:
            count = check(i-1, j, q2, count, H, W, A, rec)
            count = check(i+1, j, q2, count, H, W, A, rec)
            count = check(i, j-1, q2, count, H, W, A, rec)
            count = check(i, j+1, q2, count, H, W, A, rec)
        q = q2

main()

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
q = []
a = {}
for i in range(H):
    l = input()
    for j in range(W):
        a[j, i] = l[j]
        if l[j] == '#':
            q.append((i,j))
ans = 0
for i in range(100000000):
    if len(q) == 0:
        break
    ans+=1
    tq = []
    for qq in q:
        if qq[0] > 0:
            if a[qq[0]-1, qq[1]] == '.':
                a[qq[0] - 1, qq[1]] = '#'
                tq.append((qq[0] - 1, qq[1]))
        if qq[0] < (W-1):
            if a[qq[0]+1, qq[1]] == '.':
                a[qq[0] + 1, qq[1]] = '#'
                tq.append((qq[0] + 1, qq[1]))
        if qq[1] > 0:
            if a[qq[0], qq[1]-1] == '.':
                a[qq[0], qq[1]-1] = '#'
                tq.append((qq[0], qq[1]-1))
        if qq[1] < (H-1):
            if a[qq[0], qq[1]+1] == '.':
                a[qq[0], qq[1]+1] = '#'
                tq.append((qq[0], qq[1]+1))
    q = tq
print(ans-1)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**10
from functools import reduce

h,w,n = map(int,input().split())
sr,sc = map(int,input().split())
s = input()
t = input()
l = 1
r = w
u = 1
d = h
for s,t in zip(s[::-1],t[::-1]):
    if t == "R":
        l = max(l-1,1)
    elif t == "L":
        r = min(r+1,w)
    elif t =="U":
        d = min(d+1,h)
    else:
        u = max(u-1,1)

    if s == "L":
        l += 1
    elif s =="R":
        r -=1
    elif s =="U":
        u+=1
    else:
        d-=1
    if l > r or u > d:
        print('NO')
        exit()
if u <= sr <= d and l <= sc <= r:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
 
def main():
	h,w=IL()
	A=[S() for i in range(h)]
	U=[[False for i in range(w)] for j in range(h)]
 
	c=0
	ans=0
	for i in range(h):
    	for j in range(w):
        	if A[i][j]==".":
            	c+=1
	while c>0:
    	ans+=1
    	Bl=[]
    	for i in range(h):
        	for j in range(w):
            	if not U[i][j] and A[i][j]=="#":
                	Bl.append([i,j])
    
    	for i,j in Bl:
        	if i-1>=0:
            	if A[i-1][j]==".":
                	A[i-1][j]="#"
                	c-=1
                 
        	if j+1<=w-1:
            	if A[i][j+1]==".":
                	A[i][j+1]="#"
                	c-=1
                
        	if i+1<=h-1:
            	if A[i+1][j]==".":
                	A[i+1][j]="#"
                	c-=1
                
        	if j-1>=0:
            	if A[i][j-1]==".":
                	A[i][j-1]="#"
                	c-=1
	print(ans)
    return
    
if __name__=="__main__":
	main()

Submission status: Runtime Error

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())

def main():
	h,w=IL()
	A=[S() for i in range(h)]
	U=[[False for i in range(w)] for j in range(h)]
 
	c=0
	ans=0
	for i in range(h):
    	for j in range(w):
        	if A[i][j]==".":
            	c+=1
	while c>0:
    	ans+=1
    	Bl=[]
    	for i in range(h):
        	for j in range(w):
            	if not U[i][j] and A[i][j]=="#":
                	Bl.append([i,j])
    
    	for i,j in Bl:
        	if i-1>=0:
            	if A[i-1][j]==".":
                	A[i-1][j]="#"
                	c-=1
                 
        	if j+1<=w-1:
            	if A[i][j+1]==".":
                	A[i][j+1]="#"
                	c-=1
                
        	if i+1<=h-1:
            	if A[i+1][j]==".":
                	A[i+1][j]="#"
                	c-=1
                
        	if j-1>=0:
            	if A[i][j-1]==".":
                	A[i][j-1]="#"
                	c-=1
	print(ans)
    
if __name__=="__main__":
	main()

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
list = [input().split() for l in range(H)]
for n in range(H):
  for m in range(W):
    if list[n][m] == "#":
      list[n][m] = 1
    else:
      list[n][m] = 0

def check(l):
  c = 0
  for n in range(H):
    for m in range(W):
      if l[n][m] == 0:
        c = 1
  return c

answer = 0
while check(list) == 1:
  list_v = list
  for n in range(H):
  for m in range(W):
    if list[n][m] == 0:
      list_v[n][m] = 0
    else:
      list_v[n][m] = 1
      list_v[n+1][m] = 1
      list_v[n-1][m] = 1
      list_v[n][m+1] = 1
      list_v[n][m-1] = 1
  list = list_v
  answer += 1

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
mat = [[True] * (w+2)]
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True]*(w+2)])

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))

round = -1
while prev:
    #print(prev)
    #print(mat)
    round += 1
    next = []
    for (x,y) in prev:
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
    prev = next

print(round)

Submission status: Runtime Error

Solution code:
words = lambda t : np.array(list(map(t, input().split())))

h,w = words(int)
mat = []
mat.append([True for _ in range(w+2)])
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True for _ in range(w+2)])

#mat = np.array(mat)
#print(mat)

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))

round = -1
while not len(prev) ==  0:
    #print(prev)
    #print(mat)
    round += 1
    next = []
    for (x,y) in prev:
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
    prev = next

print(round)

Submission status: Runtime Error

Solution code:
from collections import deque
H, W = map(int ,input().split())
A = [input() for _ in range(H)]
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
inf = float("inf")

dp = [[inf]*W for _ in range(H)]
q = deque()
for y, row in enumerate(A):
    for x, c in enumerate(row):
        if c == "#":
            dp[y][x] = 0
            q.append((x, y))

while q:
    x, y = q.popleft()
    d = dp[x][y]
    for dx, dy in dxy:
        nx, ny = x+dx, y+dy
        if (not 0 <= nx < W) or (not 0 <= ny < H):
            continue
        if dp[ny][nx] <= d+1:
            continue
        dp[ny][nx] = d+1
        q.append((nx, ny))

print(max(max(row) for row in dp))

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
que = deque(maxlen=h * w)
next = deque(maxlen=h * w)

data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0

while len(que) > 0:
    count += 1
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)):
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que, next = next, que
    next.clear()

print(count - 1)

Submission status: Runtime Error

Solution code:
def isFinished( a ):
  for s in a:
    if '.' in s:
      return False
  return True


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

result = 0
  
while not isFinished( a ):
  for i in range( h ):
    for j in range( w ):
      if a[ i, j ] == '#':
        ineg = i - 1 > 0
        ipos = i + 1 < h
        jneg = j - 1 > 0
        jpos = j + 1 < w
        if ineg:
          a[ i - 1 ] = '#'
        if jneg:
          a[ i, j - 1 ] = '#'
        if ipos:
          a[ i + 1, j ] = '#'
        if jpos:
          a[ i, j + 1 ] = '#'
  result += 1
  
print( result )

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
a = [['#'] * (w + 2)] * 2
a[1: 1] = (['#'] + list(input()) + ['#'] for _ in range(h)]
d = (-1, 0), (1, 0), (0, -1), (0, 1)

step = [(i, j) for i in range(1, h + 1) for j in range(1, w + 1)
       if a[i][j] == '#']

def next_step():
    r = []
    for i, j in step:
        for di, dj in d:
            di += i
            dj += j
            if a[di][dj] == '.':
                a[di][dj] = '#'
                r.append((di, dj))
    return r

n = h * w - len(step)
r = 0
while n:
    r += 1
    step = next_step()
    n -= len(step)
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy import spatial

H, W = map(int, input().split())
board = [[s for s in input().strip()] for i in range(H)]
black = []
white = []
for i, row in enumerate(board):
  for j, c in enumerate(row):
    if c == '#':
      black.append([i,j])
    else:
      white.append([i,j])

tree = spatial.KDTree(black)
distances, indices = tree.query(white, p=1)
print(int(np.max(distances)))

Submission status: Runtime Error

Solution code:
import sklearn
print(1)

Submission status: Runtime Error

Solution code:
import numpy as np
from sklearn.neighbors import NearestNeighbors

H, W = map(int, input().split())
board = [[s for s in input().strip()] for i in range(H)]
black = []
white = []
for i, row in enumerate(board):
  for j, c in enumerate(row):
    if c == '#':
      black.append([i,j])
    else:
      white.append([i,j])

neigh = NearestNeighbors(n_neighbors=1, metric='manhattan')
neigh.fit(black)
distances, indices = neigh.kneighbors(white)
print(int(np.max(distances)))

Submission status: Runtime Error

Solution code:
import numpy as np
from sklearn.neighbors import NearestNeighbors

H, W = map(int, input().split())
board = [[s for s in input().strip()] for i in range(H)]
black = []
white = []
for i, row in enumerate(board):
  for j, c in enumerate(row):
    if c == '#':
      black.append([i,j])
    else:
      white.append([i,j])

neigh = NearestNeighbors(n_neighbors=1, metric='manhattan')
neigh.fit(black)
distances, indices = neigh.kneighbors(white)
print(distances)
print(int(np.max(distances)))

Submission status: Runtime Error

Solution code:
let
  H, W = map(x -> parse(Int, x), split(readline()))
  grid = []
  for i=1:H
    push!(grid, readline())
  end
  A = [[if grid[h][w]=='#' 0 else H*W end for w=1:W] for h=1:H]

  black = []
  white = []

  for h = 1:H
    for w = 1:W
      if A[h][w] == 0
        push!(black, (h,w))
      else
        push!(white, (h,w))
      end
    end
  end

  for w in white
    for b in black
      dis = abs(b[1] - w[1]) + abs(b[2] - w[2])
      A[w[1]][w[2]] = min(A[w[1]][w[2]], dis)
      if dis == 1
        break
      end
    end
  end

  m = 0
  for distances in A
    for d in distances
      m = max(m, d)
    end
  end

  println(m)
end

Submission status: Runtime Error

Solution code:
def a_darker_and_darker(H, W, Grid, INF=float('inf')):
    def is_in_field(row, col):
        return (0 <= row < W) and (0 <= col < H)

    grid, q = [[None] * W for _ in range(H)], []
    # 黒マスがどこにあるかを調べる。ついでにgridを初期化
    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '#':
                grid[row][col] = True
                q.append((row, col))
            else:
                grid[row][col] = False

    # '#'があるマスから上下左右に移動することを繰り返して任意のマスに到達する。
    # 何回繰り返せばすべてのマスに到達できるか？
    directions = ((-1, 0), (0, 1), (1, 0), (0, -1))  # 上右下左の隣接マスを指定
    ans = 0
    while q:
        tmp = []
        for row, col in q:
            for dr, dc in directions:
                nr, nc = row + dr, col + dc
                if is_in_field(nr, nc) and (not grid[nr][nc]):
                    grid[nr][nc] = True
                    tmp.append((nr, nc))
        ans += (1 if tmp else 0)
        q = tmp
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))

Submission status: Runtime Error

Solution code:
def a_darker_and_darker(H, W, Grid, INF=float('inf')):
    from collections import deque

    def is_in_field(row, col):
        return (0 <= row < W) and (0 <= col < H)

    q = deque()
    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '#':
                q.append((row, col, 0))

    grid = [[float('inf')] * W for _ in range(H)]
    directions = ((-1, 0), (0, 1), (1, 0), (0, -1))  # 上右下左の隣接マスを指定
    while q:
        row, col, move = q.pop()
        grid[row][col] = min(grid[row][col], move)

        for dr, dc in directions:
            nr, nc = row + dr, col + dc
            if is_in_field(nr, nc) and grid[nr][nc] == INF:
                q.appendleft((nr, nc, move + 1))
    return max([max(row) for row in grid])

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(a_darker_and_darker(H, W, Grid))

Submission status: Runtime Error

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

A = [list(map(str, input().split())) for i in range(H)]  # [['...'], ['.#.'], ['...']]

BlackList=[[0 for x in range(H+2)]for x in range(W+2)]
for i in range(W):
    for j in range(H):
        cur=A[i][0][j]
        if cur == "#":
            BlackList[i+1][j+1]=1

for i in range(W+2):
    for j in range(H+2):
      if i == 0 or i == W+1 or j == 0 or j == H+1:
        BlackList[i][j] = -1

ans=0
while True:
    continue_flag=False
    for y in range(1, H+1):
        for x in range(1, W+1):
            current = BlackList[y][x]
            if current is 1:
                BlackList[y][x] = 2

                do_control = False
                if BlackList[y][x-1] is 0:
                    BlackList[y][x - 1] = 3
                #    do_control=True
                if BlackList[y][x + 1] is 0:
                    BlackList[y][x + 1] = 3
                #    do_control = True
                if BlackList[y-1][x] is 0:
                    BlackList[y-1][x] = 3
                 #   do_control = True
                if BlackList[y+1][x] is 0:
                    BlackList[y+1][x] = 3
                #   do_control = True

                #if do_control is True:
                #    ans += 1

            elif current is 0 or current is 3:
                continue_flag=True

    if continue_flag is False:
        break
    else:
        ans += 1
        for y in range(H+2):
            for x in range(W+2):
                if BlackList[y][x] is 3:
                    BlackList[y][x] = 1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
 
def read_input():
    h, w = map(int, input().split())
    board = []
 
    for i in range(h):
        board.append([c for c in input()])
 
    return h, w, board
 
def submit():
    def check_index(t):
        if 0 <= t[0] < h and 0 <= t[1] < w:
            return True
        return False
 
    h, w, board = read_input()
 
    count = {}
    q = deque()
    for i in range(h):
        for j in range(w):
            if board[i][j] == '#':
                count[(i, j)] = 0
                q.appendleft((i, j))
            else:
                count[(i, j)] = -1
 
    while len(q) > 0:
        focus = q.pop()
 
        r = (focus[0], focus[1] + 1)
        l = (focus[0], focus[1] - 1)
        u = (focus[0] - 1, focus[1])
        d = (focus[0] + 1, focus[1])
 
 
        if check_index(r) and count[r] == -1:
            count[r] = count[focus] + 1
            q.appendleft(r)
 
        if check_index(l) and count[l] == -1:
            count[l] = count[focus] + 1
            q.appendleft(l)
 
        if check_index(u) and count[u] == -1:
            count[u] = count[focus] + 1
            q.appendleft(u)
 
        if check_index(d) and count[d] == -1:
            count[d] = count[focus] + 1
            q.appendleft(d)
 
 
    print(max(count.values()))
 
 
if __name__ == '__main__':
    submit()

Submission status: Runtime Error

Solution code:
from scipy import ndimage
import numpy as np
import sys
 
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)])
# print(A_array)
 
 
# print(A_array)
b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

Submission status: Runtime Error

Solution code:
from scipy import ndimage
import numpy as np

 
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)])
# print(A_array)
 
# print(A_array)
b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

Submission status: Runtime Error

Solution code:
from scipy import ndimage
import numpy as np

 
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)])
# print(A_array)

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

Submission status: Runtime Error

Solution code:
#入力
R,C= map(int,input().split())
c= [list(input()) for _ in range(R)]
white=[]
black=[]
for i in range(R):
  for j in range(C):
    if c[i][j]=='.':
      white.append([i,j])
    else:
      black.append([i,j])
N=len(white)
M=len(black)

ans = []

for a, b in white:
    manh = 10**9
    num = 0
    for c, d in black:
        if abs(a - c) + abs(b - d) < manh:
            manh = abs(a - c) + abs(b - d)
            #num = black.index([c, d]) + 1
    ans.append(manh)
print(max(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
H,W = map(int, input().split())
A = []
for _ in range(H):
    v = 0
    for w, x in zip(range(W), input()):
        if x == "#":
            v |= 1 << w
    A += [ v ]

import numpy as np


A = np.array(A)
WK = np.zeros(A.shape)
MASK = pow(2, W) - 1
MASKSUM = MASK * H
i = 0
while True:
    if np.sum(A) == MASKSUM:
        break
    WK = 0+A
    A[:-1] |= WK[1:]
    A[1:] |= WK[:-1]
    A |= ((WK << 1)&MASK) | (WK >> 1)
    i += 1

print(i)

Submission status: Runtime Error

Solution code:
import copy
 
h, w = map(int, input().split())
 
lists = []
cnt = 0
mozi = ""
size = h * w
kaiseki = []
kaiseki2 = []
 
for i in range(h):
    s = input()
    mozi += s
 
lists = list(mozi)
 
 
for i in range(size):
    if lists[i] == "#":
        kaiseki.append(i)
 
 
while True:
    result = set(lists)
    if len(result) == 1:
        break
    cnt += 1
    for i in range(len(kaiseki)):
        if int(kaiseki[i]) - w >= 0:
            lists[int(kaiseki[i]) - w] = "#"
            kaiseki2.append(int(kaiseki[i]) - w)
        if int(kaiseki[i]) + w <= size - 1:
            lists[int(kaiseki[i]) + w] = "#"
            kaiseki2.append(int(kaiseki[i]) + w)
        amari = int(kaiseki[i]) % w
        if amari != 0:
            lists[int(kaiseki[i]) - 1] = "#"
            kaiseki2.append(int(kaiseki[i]) - 1)
        if amari != w-1:
            lists[int(kaiseki[i]) + 1] = "#"
            kaiseki2.append(int(kaiseki[i]) + 1)
    kaiseki.clear()
    kaiseki = kaiseki2.copy()
    kaiseki2.clear()
 
print(cnt)

Submission status: Runtime Error

Solution code:
def main():
    H, W = map(int, input().split())
    A = [list(input()) for x in range(H)]
    distance = []
    for y in range(H):
        for x in range(W):
            if A[y][x] == '.':
                d = []
                for dy in range(0, H):
                    for dx in range(0, W):
                        if x + dx < W and y + dy < H:
                            if A[y + dy][x + dx] == '#':
                                d.append(dx + dy)

                        if x + dx < W and y - dy >= 0:
                            if A[y - dy][x + dx] == '#':
                                d.append(dx + dy)

                        if x - dx >= 0 and y + dy < H:
                            if A[y + dy][x - dx] == '#':
                                d.append(dx + dy)

                        if y - dy >= 0 and x - dx >= 0:
                            if A[y - dy][x - dx] == '#':
                                d.append(dx + dy)

                # print(y, x, d)
                distance.append(min(d))
    print(max(distance))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

H,W=map(int,input().split())
max_value = H+W
matrix =[]

for _ in range(H):
    matrix.append([0 if i == '#' else max_value for i in list(input())])
matrix = np.array(matrix)

for c in range(W-1):
    matrix[:,c+1] = np.minimum(matrix[:,c]+1,matrix[:,c+1])
for c in range(W-1,0,-1):
    matrix[:,c-1] = np.minimum(matrix[:,c-1],matrix[:,c]+1)
for r in range(H-1):
    matrix[x+1,:] = np.minimum(matrix[r,:]+1,matrix[r+1,:])
for r in range(H-1,0,-1):
    matrix[r-1,:] = np.minimum(matrix[r,:]+1,matrix[r-1,:])
print(np.max(matrix))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
H,W = list(map(int,input().split()))
A = []
for i in range(H):
  A.append(list(input()))
n = 0
B = []
C = []
for y, row in enumerate(A):
  for z,x in enumerate(row):
    if x == "#":
      pos = (y,z)
      B.append(pos)
    else:
      pos = (y,z)
      C.append(pos)
while True:
  D = []
  for i in range(len(C)):
    try:
      w,v = C[i]
      if (w + 1,v) in B or (w -1,v) in B or (w,v + 1) in B or (w,v - 1) in B:
        A[w][v] = "#"
        value = (w,v)
        D.append(value)
        print(B,n)
    except IndexError:
      pass
  n += 1
  B = B + D
  for i in range(len(D)):
    C.remove(D[i])
  if len(B) == H * W:
    break
 
print(n)
# -*- coding: utf-8 -*-
H,W = list(map(int,input().split()))
A = []
for i in range(H):
  A.append(list(input()))
n = 0
B = []
C = []
for y, row in enumerate(A):
  for z,x in enumerate(row):
    if x == "#":
      pos = (y,z)
      B.append(pos)
    else:
      pos = (y,z)
      C.append(pos)
while True:
  D = []
  for i in range(len(C)):
    try:
      w,v = C[i]
      if (w + 1,v) in B or (w -1,v) in B or (w,v + 1) in B or (w,v - 1) in B:
        A[w][v] = "#"
        value = (w,v)
        D.append(value)
    except IndexError:
      pass
  n += 1
  B = B + D
  for i in range(len(D)):
    C.remove(D[i])
  if len(B) == H * W:
    break
 
print(n)

Submission status: Runtime Error

Solution code:
import numpy as np

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

data = np.zeros((3*h,3*w),dtype=np.int)
datamap = np.ones((3*h,3*w),dtype=np.int)

datamaplt = np.ones((3*h,3*w),dtype=np.int)
datamaplt = datamaplt*(10)
datamaprt = np.ones((3*h,3*w),dtype=np.int)
datamaprt = datamaprt*(10)
datamaplb = np.ones((3*h,3*w),dtype=np.int)
datamaplb = datamaplb*(10)
datamaprb = np.ones((3*h,3*w),dtype=np.int)
datamaprb = datamaprb*(10)

for i in range(h):
    for  j in range(w):
        if data_t[i][j] == "#":
            data[h+i,w+j] = 1
        datamaplt[h+i,w+j] = 0
        datamaprt[h+i,w+j] = 0
        datamaplb[h+i,w+j] = 0
        datamaprb[h+i,w+j] = 0
        

for i in range(h):
    for  j in range(w):
        ii = i+h
        jj = j+w
        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+h
        jj = j+w
        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+h
        jj = j+w
        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+h
        jj = j+w
        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+h
        jj = j+w
        if min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj]) > ans:
            ans =  min(datamaplt[ii,jj],datamaprt[ii,jj],datamaplb[ii,jj],datamaprb[ii,jj])
            
print(ans)