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:
#!/usr/bin/env python3
import sys
import bisect
import heapq

def solve(H: int, W: int, A: "List[str]"):
    Q = []
    marked = [[0] * W for h in range(H)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                heapq.heappush(Q, (0, h, w))
                marked[h][w] = 1
    dmax = 0
    while len(Q) > 0:
        d, h, w = heapq.heappop(Q)
        dmax = max(d, dmax)
        if h-1 >= 0 and marked[h-1][w] == 0:
            heapq.heappush(Q, (d+1, h-1, w))
            marked[h-1][w] = 1
        if w-1 >= 0 and marked[h][w-1] == 0:
            heapq.heappush(Q, (d+1, h, w-1))
            marked[h][w-1] = 1
        if h+1 <= H-1 and marked[h+1][w] == 0:
            marked[h+1][w] = 1
            heapq.heappush(Q, (d+1, h+1, w))
        if w+1 <= W-1 and marked[h][w+1] == 0:
            marked[h][w+1] = 1
            heapq.heappush(Q, (d+1, h, w+1))
    print(dmax)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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]"
    solve(H, W, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

A = [list(str(input())) for i in range(H)]

white = []
black = []

length = sum([a.count(".") for a in A])
cnt = 0

while (length > 0):
    gray = []
    for i in range(W):
        for j in range(H):
            if A[i][j] == "#":
                black.append([i,j])
            else:
                white.append([i,j])
       
    for l in white:
        if [l[0],l[1]-1] in black or [l[0],l[1]+1] in black or [l[0]-1,l[1]] in black or [l[0]+1,l[1]] in black:
            gray.append(l)

    for l in gray:
        black.append(l)
        white.remove(l)
        
    cnt += 1
    length = len(white)
    
print(cnt)

Submission status: Runtime Error

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

L = [0]
R = [0]
m = []
l = []
end = 0
for i in range(H):
    h = list(input())
    m.append(h)
    for j, w in enumerate(h):
        if w == '#':
            l.append([i, j])
            end += 1
HW = H * W
ans = 0
while (end < HW):
    nl = []
    for ll in l:
        if (0 < ll[0]):
            if (m[ll[0] - 1][ll[1]] == '.'):
                m[ll[0] - 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] - 1, ll[1]])

        if (ll[0] < W - 1):
            if (m[ll[0] + 1][ll[1]] == '.'):
                m[ll[0] + 1][ll[1]] = '#'
                end += 1
                nl.append([ll[0] + 1, ll[1]])

        if (0 < ll[1]):
            if (m[ll[0]][ll[1] - 1] == '.'):
                m[ll[0]][ll[1] - 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] - 1])

        if (ll[1] < H - 1):
            if (m[ll[0]][ll[1] + 1] == '.'):
                m[ll[0]][ll[1] + 1] = '#'
                end += 1
                nl.append([ll[0], ll[1] + 1])
        l = nl
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
height, width = map(int, input().split())
A = []
blacks = []
for r_index in range(width):
    row = list(input())
    b = [column_index for column_index, value in enumerate(row) if value == '#']
    A.append(row)
    for i in b:
        blacks.append([r_index,i])

max_length = 0

for h in range(height):
    for w in range(width):
        if A[h][w] == 'w':
            continue
        min_length = height + width
        for black in blacks:
            min_length = min(min_length, abs(h - black[0]) + abs(w - black[1]))
        max_length = max(max_length, min_length)

print(max_length)

Submission status: Runtime Error

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

A = [str(input()) for i in range(H)]

def next_black(B, i, j, c):
    if c >= B[j][i]:
        return B
    else:
        B[j][i] = c
        if i + 1 < W:
            next_black(B, i + 1, j, c + 1)
        if i - 1 >= 0:
            next_black(B, i - 1, j, c + 1)
        if j + 1 < H:
            next_black(B, i, j + 1, c + 1)
        if j - 1 >= 0:
            next_black(B, i, j - 1, c + 1)
    
    return B

max_count = H + W -2
B = [[max_count for i in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[j][i] == '#':
            next_black(B, i, j, 0)

ans = 0
for i in B:
    if max(i) >= ans:
        ans = max(i)

print(ans)

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)

pass


max_val = pow(10, 6)

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

    return tmp

ary = convert_ary(ary)

def upd_left(ary, y, x):
    if x == 0:
        return ary
    if ary[y][x-1] is None:
        ary[y][x-1] = ary[y][x] + 1
    else:
        ary[y][x-1] = min(ary[y][x-1], ary[y][x] + 1)
    return ary

def upd_right(ary, y, x):
    if x == w - 1:
        return ary
    if ary[y][x+1] is None:
        ary[y][x+1] = ary[y][x] + 1
    else:
        ary[y][x+1] = min(ary[y][x+1], ary[y][x] + 1)
    return ary

def upd_up(ary, y, x):
    if y == 0:
        return ary
    if ary[y-1][x] is None:
        ary[y-1][x] = ary[y][x] + 1
    else:
        ary[y-1][x] = min(ary[y-1][x], ary[y][x] + 1)
    return ary

def upd_down(ary, y, x):
    if y == h - 1:
        return ary
    if ary[y+1][x] is None:
        ary[y+1][x] = ary[y][x] + 1
    else:
        ary[y+1][x] = min(ary[y+1][x], ary[y][x] + 1)
    return ary

from copy import deepcopy

def update_ary(ary):
    tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] is None:
                continue
            tmp = upd_left(ary, y, x)
            tmp = upd_right(ary, y, x)
            tmp = upd_up(ary, y, x)
            tmp = upd_down(ary, y, x)
    return tmp

def is_complete(ary):
    for line in ary:
        if None in line:
            return False
    return True

while not is_complete(ary):
    ary = update_ary(ary)

print(max(elem for line in ary for elem in line))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys 


def main():
    H, W = [int(x) for x in sys.stdin.readline.split()]
    board = [[0 for i in range(H)] for j in range(W)]

    """ #は1, .は0 """
    for i in range(H):
        X = sys.stdin.readline
        for j in range(len(X)):
            if X[j] == "#":
                board[i][j] = 1

    num_board = np.array(board)
    height, width = num_board.shape[:2]
    count = 0
    height_r, width_r = range(height), range(width)
    while (np.sum(num_board) != height*width):
        num_board_ans = np.zeros((height, width))
        for i in height_r:
            for j in width_r:
                if num_board[i, j] == 1:
                    num_board_ans[i, j] = 1
                    a = max(i-1, 0)
                    num_board_ans[a, j] = 1
                    b = max(j-1, 0)
                    num_board_ans[i, b] = 1
                    c = min(i+1, height-1)
                    num_board_ans[c, j] = 1
                    d = min(j+1, width-1)
                    num_board_ans[i, d] = 1
        num_board = num_board_ans
        count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import copy
a = list(map(int, input().split()))
c=[input() for i in range(a[1])]
b=[]
for i in range(a[1]):
  b.append(list(c[i]))
z=1
t=0
f=0
while z==1:
  f=0
  for h in range(a[0]):
    for w in range(a[1]):
      #print(t,h,w,b[t%2])
      if b[h][w]=='#':
        if h>0 and b[h-1][w] != '#':
          b[h-1][w]='#'
          f=1
        if h<a[1]-1 and b[h+1][w] != '#':          
          b[h+1][w]='#'
          f=1
        if w>0 and b[h][w-1] != '#':  
          b[h][w-1]='#'
          f=1
        if w<a[1]-1 and b[h][w+1] != '#':   
          b[h][w+1]='#'
          f=1
  if f==0:
    print(t)
    break
  t=t+1

Submission status: Runtime Error

Solution code:
import copy
h,w=map(int,input().split())
a=[list(map(lambda x:0 if x=="#" else 1,input())) for i in range(h)]
b=[[0 for i in range(w)] for j in range(h)]
count=0
while a!=b:
  z=copy.deepcopy(a)
  for i in range(h):
    for j in range(w):
      a[i][j]=z[i][j]*(z[i-1][j] if i!=0 else 1)*(z[i+1][j] if i!=h-1 else 1)*(z[i][j-1] if j!=0 else 1)*(z[i][j+1] if j!=h-1 else 1)
  count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

black_list = []
used = []

for i in range(h):
  for j in range(w):
    if a[i][j] == ".":
      a[i][j] = 1
    else:
      a[i][j] = 0
      black_list.append([i, j])
a = np.array(a)

def search(a, h, w):
  a = np.array(a)
  b = np.array(a[:]).T
  for i in range(w):
    for j in range(1, h-1):
      if a[i][j] == 0:
        a[i][j-1] = 0
        a[i][j+1] = 0

  for i in range(h):
    for j in range(1, w-1):
      if b[i][j] == 0:
        b[i][j-1] = 0
        b[i][j+1] = 0
  return a*b.T

count = 0
while np.sum(a) > 0:
  a = search(a, h, w)
  count += 1

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import collections
import copy
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(H)]
rinsetsu=np.zeros((H*W,H*W),dtype="bool")
F=np.zeros((1,H*W),dtype="bool")

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
while 1:
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break

Submission status: Runtime Error

Solution code:
v = [int(d) for d in input().split()]
f = []

for e in range(v[0]):
    f.append(list(input()))

n = 0
k = []
while True:
    for b in range(v[0]):
        for a in range(v[1]):
            if f[a][b] == '#':
                k.append((a-1,b))
                k.append((a+1,b))
                k.append((a,b-1))
                k.append((a,b+1))

    for u in k:
        if  u[0] < 0 or u[0] > v[1]-1:
            continue
        elif u[1] < 0 or u[1] > v[0]-1:
            continue
        elif f[u[0]][u[1]] == "#":
            continue

        else:
            f[u[0]][u[1]] = "#"
            
    n += 1
    ee = []
    for qq in f:
        ee.extend(qq)

    if "." not in ee:
        break

print(n)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list(map(int,input().split())))
cnt=0
lst=['#']*w
if h>=2 and w>=2:
  for j in range(1,h-1):
    for k in range(1,w-1):
      if all(a[l]==lst for l in range(h)):
        break
      elif a[j][k]=='#':
        a[j-1][k]='#'
        a[j+1][k]='#'
        a[j-1][k-1]='#'
        a[j-1][k]='#'
        a[j-1][k+1]='#'
        a[j+1][k-1]='#'
        a[j+1][k]='#'
        a[j+1][k+1]='#'
        cnt+=1
  print(cnt)
elif h==1:
  print(2-a.count('#'))
else:
  print(2-a[0].count('#')-a[1].count('#'))

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
A = []
for i in range(H):
  a = list(input())
  A.append(a)
def f(h,w):
  global H,W,A
  res = 0
  for i in range(H*W):
    for x in range(-i,i+1):
      for y in range(-i,i+1):
        if abs(x)+abs(y)>i:
          continue
        hx,wx = h+x,w+y
        if hx<0 or H<=hx or wx<0 or W<=wx:
          continue
        if A[hx][wx]=='#':
          res = i
          break
      if res>0:
        break
    if res>0:
      break
  return res
ans = []
for h in range(H):
  for w in range(W):
    if A[h][w]=='.':
      ans.append(f(h,w))
print(max(ans))

Submission status: Runtime Error

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

# In[132]:


import numpy as np
import copy


# In[133]:


H,W = map(int, input().split())
A = [input().split() for i in range(H)]
A = np.array(A)


# In[189]:


B = np.full((H+2, W+2), '.')
B[1:-1, 1:-1] = A
C = copy.deepcopy(B)
count = 0

while np.all(B[1:-1, 1:-1] == '#') == False:
    count += 1
    for index in np.stack([np.where(B == '#')[0], np.where(B == '#')[1]]).T:
        C[index[0]-1, index[1]] = '#'
        C[index[0]+1, index[1]] = '#'
        C[index[0], index[1]-1] = '#'
        C[index[0], index[1]+1] = '#'     
        #print(C)
    C[0,:] = '.'
    C[-1,:] = '.'
    C[:,0] = '.'
    C[:,-1] = '.'
    #print(C)
    B = C[:,:]
    #print(count)
print(count)


# In[ ]:

Submission status: Runtime Error

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

def dfs(i, j):
  l = [[i, j, 0]]
  ret = []
  while len(l) > 0:
    p = l.pop()
    if p[0] < 0 or p[1] < 0 or p[0] > H - 1 or p[1] > W - 1 or memo[p[0]][p[1]] or p[2] > H + W - 1:
      continue
    if A[p[0]][p[1]] == "#":
      ret.append(p[2])
    memo[p[0]][p[1]] = True
    l.append([p[0] - 1, p[1], p[2] + 1])
    l.append([p[0] + 1, p[1], p[2] + 1])
    l.append([p[0], p[1] - 1, p[2] + 1])
    l.append([p[0], p[1] + 1, p[2] + 1])
  return min(ret)
    

ans = 0
for i in range(H):
  for j in range(W):
    if A[i][j] == ".":
      memo = [[False for _ in range(W)] for _ in range(H)]
      ans = max(ans, dfs(i, j))

print(max(ans - 1, 0))

Submission status: Runtime Error

Solution code:

def input_from_console():
    h, w = map(int, input().split())
    m = list()
    for i in range(h):
        m.append(list(input()))

    return h, w, m


def get_count(h, w, m):
    count = 0
    for i in range(h):
        count += sum([1 for item in m[i] if item == '#'])
    return count


def check(i, j, m, ):
    for ii in [-1, 1]:
        if i + ii < 0 or i + ii > len(m[0]) - 1:
            continue
        if m[i + ii][j] == "#":
            return True

    for jj in [-1, 1]:
        if j + jj < 0 or j + jj > len(m) - 1:
            continue
        if m[i][j + jj] == "#":
            return True
    return False


def main():
    h, w, m = input_from_console()
    total = h * w
    count = 0

    while True:
        flip_list = []
        for i in range(h):
            for j in range(w):
                if check(i, j, m):
                    flip_list.append([i,j])
                    # print(flip_list)
        for item in flip_list:

            m[item[0]][item[1]] = '#'
        count += 1
        # print("count", count, get_count(h, w, m), m)
        if get_count(h, w, m) == total:
            print(count)
            break

    # print(h, w)
    # print(m)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H, W = map(int,input().split())
stonelist = [["0"]*H]*W

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

def mklist(H,W):
    alllist = []
    for i in range(H):
        for n in range(W):
            alllist.append([i,n])
    return alllist

def black_position(H, W, stonelist):
    bposlist = []
    for i in range(H):
        for n in range(W):
            if stonelist[i][n] == "#":
                bposlist.append([i,n])
    return bposlist

def white_position(H, W, stonelist):
    wposlist = []
    for i in range(H):
        for n in range(W):
            if stonelist[i][n] == ".":
                wposlist.append([i,n])
    return wposlist

def change_black(H, W, bposlist):
    rnum = 0
    blen = len(bposlist)
    for l in range(blen):
        if bposlist[l][0] - 1 >= 0:
            if bposlist.count([(bposlist[l][0] - 1) , (bposlist[l][1])]) == 0:
                bposlist.append([(bposlist[l][0] - 1) , (bposlist[l][1])])
        if bposlist[l][1] - 1 >= 0:
            if bposlist.count([(bposlist[l][0]) , (bposlist[l][1] - 1)]) == 0:
                bposlist.append([(bposlist[l][0]) , (bposlist[l][1] - 1)])
        if bposlist[l][0] + 1 <= W-1:
            if bposlist.count([(bposlist[l][0] + 1), (bposlist[l][1])]) == 0:
                bposlist.append([(bposlist[l][0] + 1), (bposlist[l][1])])
        if bposlist[l][1] + 1 <= H-1:
            if bposlist.count([(bposlist[l][0]), (bposlist[l][1] + 1)]) == 0:
                bposlist.append([(bposlist[l][0]), (bposlist[l][1] + 1)])
    return bposlist

def check_matrix(alllist, bposlist):
    if len(alllist) == len(bposlist):
        return 1
    else:
        return 0

def ch_all(H, W, alllist,bposlist):
    cnt = 0
    tmpposlist = []
    while (check_matrix(alllist, tmpposlist) == 0):
        tmpposlist = change_black(H, W, bposlist)
        cnt = cnt + 1
    return cnt

alist = mklist(H,W)
bpos = black_position(H, W, stonelist)
wpos = white_position(H, W, stonelist)

#print(ch_all(H, W, alist,bpos))

if wpos == []:
    print(0)
else:
    print(ch_all(H, W, alist,bpos))

Submission status: Runtime Error

Solution code:
current_blackcells = []
WHOLE_HIGHT = 0
WHOLE_WIDTH = 0
WHOLE_CELLS = 0
COUNT = 0


def main():
    global WHOLE_HIGHT
    global WHOLE_WIDTH
    global WHOLE_CELLS
    global COUNT
    WHOLE_HIGHT, WHOLE_WIDTH = map(int, input().split())
    WHOLE_CELLS = WHOLE_HIGHT*WHOLE_WIDTH
    cells_list = []

    for hight in range(WHOLE_HIGHT):
        cells = input()
        search_black_cell(hight, cells)
        cells_list.append(cells)

    b2w(current_blackcells)

    print(COUNT)


def search_black_cell(hight, cells):
    b_index = cells.find('#')
    if(b_index == -1):
        return
    current_blackcells.append((hight, b_index))
    search_black_cell(hight, cells[b_index+1:])


def b2w(blackcells):
    global COUNT
    global WHOLE_HIGHT
    global WHOLE_WIDTH
    global current_blackcells
    if len(current_blackcells) == WHOLE_CELLS:
        return
    new_blackcells = []
    print(current_blackcells)
    COUNT += 1
    for cell in blackcells:
        hight = cell[0]
        width = cell[1]
        # 縦から処理
        if(hight+1 < WHOLE_HIGHT):
            new_blackcells.append((hight+1, width))
        if(hight-1 >= 0):
            new_blackcells.append((hight-1, width))
        # 横処理
        if(width+1 < WHOLE_WIDTH):
            new_blackcells.append((hight, width+1))
        if(width-1 >= 0):
            new_blackcells.append((hight, width-1))

    new_blackcells = list(set(new_blackcells) - set(current_blackcells))
    current_blackcells = current_blackcells + new_blackcells
    b2w(new_blackcells)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import copy
h,w=map(int,input().split())
a=[list(map(lambda x:0 if x=="#" else 1,input())) for i in range(h)]
b=[[0 for i in range(w)] for j in range(h)]
count=0
print(a)
while a!=b:
  z=copy.deepcopy(a)
  for i in range(h):
    for j in range(w):
      a[i][j]=z[i][j]*(z[i-1][j] if i!=0 else 1)*(z[i+1][j] if i!=h-1 else 1)*(z[i][j-1] if j!=0 else 1)*(z[i][j+1] if j!=h-1 else 1)
  count+=1
print(count)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
A=[[["."] *w for j in range(h)] for i in range(10)]
A[0]=[list(input()) for _ in range(h)]


i=0
ans=0
while A[i]!=[["#"] *w for j in range(h)]:
  for takasa in range(h):
    for nanmojime in range(w):
      if A[i][takasa][nanmojime]=="#":
        if nanmojime==0 and takasa==0:
          A[i+1][0][1]="#"
          A[i+1][1][0]="#"
          A[i+1][0][0]="#"
        elif nanmojime==0 and takasa==h-1:
          A[i+1][h-2][0]="#"
          A[i+1][h-1][1]="#"
          A[i+1][h-1][0]="#"
        elif nanmojime==w-1 and takasa==0:
          A[i+1][0][w-2]="#"
          A[i+1][1][w-1]="#"
          A[i+1][0][w-1]="#"
        elif nanmojime==w-1 and takasa==h-1:
          A[i+1][h-1][w-2]="#"
          A[i+1][h-2][w-1]="#"
          A[i+1][h-1][w-1]="#"
        elif takasa==0:
          A[i+1][0][nanmojime-1]="#"
          A[i+1][0][nanmojime+1]="#"
          A[i+1][1][nanmojime]="#"
          A[i+1][0][nanmojime]="#"
        elif takasa==h-1:
          A[i+1][h-1][nanmojime-1]="#"
          A[i+1][h-1][nanmojime+1]="#"
          A[i+1][h-2][nanmojime]="#"
          A[i+1][h-1][nanmojime]="#"
        elif nanmojime==0:
          A[i+1][takasa-1][0]="#"
          A[i+1][takasa+1][0]="#"
          A[i+1][takasa][1]="#"
          A[i+1][takasa][nanmojime]="#"
        elif nanmojime==w-1:
          A[i+1][takasa-1][w-1]="#"
          A[i+1][takasa+1][w-1]="#"
          A[i+1][takasa][w-2]="#"
          A[i+1][takasa][nanmojime]="#"
        else:
          A[i+1][takasa-1][nanmojime]="#"
          A[i+1][takasa+1][nanmojime]="#"
          A[i+1][takasa][nanmojime-1]="#"
          A[i+1][takasa][nanmojime+1]="#"
          A[i+1][takasa][nanmojime]="#"

  i+=1
print(i)
print(A)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# input
n, w = map(int, input().split())
a = [[i] * w for i in range(n)]
for i in range(n):
    a[i] = [str(b) for b in input()]

cnt = 0
blk = 0
while blk <= n * w:

    m1 = [0] * int(n * w)
    m2 = [0] * int(w * w)
    blk = 0
    for i in range(n):
        for j in range(w):
            if a[i][j] == '.':
                m1[blk] = i
                m2[blk] = j
                blk += 1

    if blk == n * w:
        break

    for i in range(blk):
        for j in range(2):
            r = m1[i] + (2 * j - 1)
            c = m2[i] + (2 * j - 1)
            if 0 <= r < n:
                if a[r][m2[i]] == '#':
                    a[m1[i]][m2[i]] = '#'
                    break
            if 0 <= c < w:
                if a[m1[i]][c] == '#':
                    a[m1[i]][m2[i]] = '#'
                    break

    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
def manhattand(arg1,arg2):
    x1 = arg1[0]
    y1 = arg1[1]
    x2 = arg2[0]
    y2 = arg2[1]
    return (abs(x2-x1)+abs(y1-y2))


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

list1 = []
listk = []

for i in range(H):
    a = input()
    list2 = []
    for j in range(W):
        list2.append(a[j])
        if a[j] == "#":
             listk.append((i,j))
    list1.append(list2)


maxdd = 0
for k in range(H):
    for l in range(W):
        if (list1[k][l]) == ".":
            maxd = manhattand(listk[0], (k,l))
            for m in range(len(listk)):
                maxd = min(maxd,manhattand(listk[m], (k,l)))
        maxdd = max(maxdd, maxd)

print(maxdd)

Submission status: Runtime Error

Solution code:
H, W = list(map(int, input().split()))
A = []
for i in range(H):
    A.append(list(input().split()[0]))

import numpy as np
indexes = list(map(list, np.array(np.where(np.array(A) == '#')).T))

cnt = 0
flag = False

while not flag:
    for i, j in indexes:
        if i == 0 and j == 0:
            A[i + 1][j] = '#'
            A[i][j + 1] = '#'
        elif i == 0 and j == W - 1:
            A[i + 1][j] = '#'
            A[i][j - 1] = '#'
        elif i == H - 1 and j == 0:
            A[i - 1][j] = '#'
            A[i][j + 1] = '#'
        elif i == H - 1 and j == W - 1:
            A[i - 1][j] = '#'
            A[i][j - 1] = '#'
        elif i == 0:
            A[i + 1][j] = '#'
            A[i][j + 1] = '#'
            A[i][j - 1] = '#'
        elif j == 0:
            A[i + 1][j] = '#'
            A[i - 1][j] = '#'
            A[i][j + 1] = '#'
        elif i == H - 1:
            A[i - 1][j] = '#'
            A[i][j + 1] = '#'
            A[i][j - 1] = '#'
        elif j == W - 1:
            A[i + 1][j] = '#'
            A[i - 1][j] = '#'
            A[i][j - 1] = '#'
        else:
            A[i + 1][j] = '#'
            A[i - 1][j] = '#'
            A[i][j + 1] = '#'
            A[i][j - 1] = '#'
    cnt += 1
    flag = all([all(np.array(A)[i] == '#') for i in range(len(A))])
    indexes = set(map(tuple, list(map(list, np.array(np.where(np.array(A) == '#')).T)))) - set(map(tuple, indexes))

print(cnt)

Submission status: Runtime Error

Solution code:
import copy
a = list(map(int, input().split()))
c=[input() for i in range(a[1])]
d=[]
for i in range(a[1]):
  d.append(list(c[i]))
b=[copy.deepcopy(d),copy.deepcopy(d)]
z=1
t=0
f=0
while z==1:
  f=0
  for h in range(a[0]):
    for w in range(a[1]):
      print(t,h,w,b[t%2])
      if b[t%2][h][w]=='#':
        if h>0 and b[(t+1)%2][h-1][w] != '#':
          b[(t+1)%2][h-1][w]='#'
          f=1
        if h<a[1]-1 and b[(t+1)%2][h+1][w] != '#':          
          b[(t+1)%2][h+1][w]='#'
          f=1
        if w>0 and b[(t+1)%2][h][w-1] != '#':  
          b[(t+1)%2][h][w-1]='#'
          f=1
        if w<a[1]-1 and b[(t+1)%2][h][w+1] != '#':   
          b[(t+1)%2][h][w+1]='#'
          f=1
  if f==0:
    print(t-1)
    break
  t=t+1

Submission status: Runtime Error

Solution code:
import numpy as np

h,w=map(int,input().split())
maze=[list(input()) for i in range(w)]
s= np.empty((0,2), int)
#print(maze)
for i in range(w):
    for j in range(h):
        if maze[i][j]=="#":
            s= np.append(s, np.array([[i,j]]), axis=0)
l= np.empty((h*w,0), int)
#print(maze,s)
for i in range(w):
    for j in range(h):
        cnt=10**7
        if maze[i][j]==".":
            vec=s-np.array([i,j])
            vec=np.abs(vec)
            ans=np.sum(vec,axis=1)
            l=np.append(l,np.min(ans))
print(np.max(l))

Submission status: Runtime Error

Solution code:
import copy
H,W = map(int, input().split())
hoge1 = []
for i in range(0,H):
	a = input()
	x = [a[i:i+1] for i in range(len(a))]
	hoge1.append(x)

def procb(h,w,hoge1,hoge2):
	if h == 0 and w == 0 and hoge1[h][w] == '#':
		hoge2[0][1] = '#'
		hoge2[1][0] = '#'
	elif h == 0 and w == W-1 and hoge1[h][w] == '#':
		hoge2[0][w-1] = '#'
		hoge2[1][w]   = '#'
	elif h == H-1 and w == 0 and hoge1[h][w] == '#':
		hoge2[h-1][0] = '#'
		hoge2[h][1] = '#'
	elif h == H-1 and w == W-1 and hoge1[h][w] == '#':
		hoge2[h-1][w] = '#'
		hoge2[h][w-1] = '#'
	elif h == 0 and hoge1[h][w] == '#':
		hoge2[h][w-1] = '#'
		hoge2[h][w+1] = '#'
		hoge2[h+1][w] = '#'
	elif h == H-1 and hoge1[h][w] == '#':
		hoge2[h][w-1] = '#'
		hoge2[h][w+1] = '#'
		hoge2[h-1][w] = '#'
	elif w == 0 and hoge1[h][w] == '#':
		hoge2[h-1][w] = '#'
		hoge2[h+1][w] = '#'
		hoge2[h][w+1] = '#'
	elif w == W-1 and hoge1[h][w] == '#':
		hoge2[h-1][w] = '#'
		hoge2[h+1][w] = '#'
		hoge2[h][w-1] = '#'
	elif hoge1[h][w] == '#':
		hoge2[h-1][w] = '#'
		hoge2[h+1][w] = '#'
		hoge2[h][w-1] = '#'
		hoge2[h][w+1] = '#'


cnt = 0
hoge2 = copy.deepcopy(hoge1)
for epoc in range(max(H,W)):
	for h in range(H):
		for w in range(W):
			procb(h,w,hoge1,hoge2)

	hoge1 = copy.deepcopy(hoge2)
	cnt += 1

	x = 0
	for i in hoge1:
		if '.' in i:
			x = 1

	if x == 0:
		break

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    H, W = [int(x) for x in input().split()]
    board = [[0 for i in range(H)] for j in range(W)]

    """ #は1, .は0 """
    for i in range(H):
        X = input()
        for j in range(len(X)):
            if X[j] == "#":
                board[i][j] = 1

    num_board = np.array(board)
    height, width = num_board.shape[:2]
    count = 0
    height_r, width_r = range(height), range(width)
    while (np.sum(num_board) != height*width):
        num_board_ans = np.zeros((height, width))
        for i in height_r:
            for j in width_r:
                if num_board[i, j] == 1:
                    num_board_ans[i, j] = 1
                    a = max(i-1, 0)
                    num_board_ans[a, j] = 1
                    b = max(j-1, 0)
                    num_board_ans[i, b] = 1
                    c = min(i+1, height-1)
                    num_board_ans[c, j] = 1
                    d = min(j+1, width-1)
                    num_board_ans[i, d] = 1
        num_board = num_board_ans
        count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import collections
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(W)]
rinsetsu=np.zeros((H*W,H*W),dtype="bool")
F=np.zeros((1,H*W),dtype="bool")

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
while 1:
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break

Submission status: Runtime Error

Solution code:
import numpy as np
import copy
H,W = input().split()
H = int(H)
W = int(W)
s = [input() for i in range(H)]
text = s[1]
HW = np.zeros([H,W])
for i in range(H):
  for j in range(W):
    if s[i][j] == '.': #白
      HW[i,j] = 0
    else:
      HW[i,j] = 1 #黒

k = HW.sum()
HW_alpha = np.zeros([H+2,W+2])
HW_alpha[1:-1,1:-1]=copy.deepcopy(HW)
num = 0
while int(k) != H*W:
  for i in range(H):
    for j in range(W):
      if HW[i,j] == 1.:
        HW_alpha[i,j+1] = 1
        HW_alpha[i+2,j+1] = 1
        HW_alpha[i+1,j] = 1
        HW_alpha[i+1,j+2] = 1
  HW=copy.deepcopy(HW_alpha[1:-1,1:-1])
  num = num +1
  k = HW.sum()

print(num)