Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

3



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


Sample output:
2

Submission status: Runtime Error

Solution code:
import copy

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

grid = [[False] * (w + 2)]
for _ in range(w):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

cnt = 0
while True:
    flag = True
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # print('#' if grid[i][j] else '.', end='')
            if grid[i][j] is False:
                flag = False
        # print()
    if flag:
        break

    new_grid = copy.deepcopy(grid)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] is True:
                new_grid[i][j + 1] = True
                new_grid[i][j - 1] = True
                new_grid[i + 1][j] = True
                new_grid[i - 1][j] = True
    grid = new_grid
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
H, W = (int(_) for _ in input().split())  
l = [list(input()) for i in range(H)]
b = [[h,w] for h in range(H) for w in range(W) if l[h][w]=="#"]
w = [[h,w] for h in range(H) for w in range(W) if l[h][w]=="."]
print(max([min([abs(i[0]-ii[0])+abs(i[1]-ii[1]) for i in b]) for ii in w]))

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w = na()

a = []

for i in range(h):
  s = ns()
  b = []
  for j in s:
    if j == '#':
      b.append(1)
    if j == '.':
      b.append(0)
  a.append(b)

t = []
c = 2
while(True):
  p = True
  for i in range(w):
    for j in range(h):
      if a[i][j] == 0:
        p = False
        k = 1
        if i > 0 and a[i-1][j] > 0 and a[i-1][j] < c:
          k = c
        if j > 0 and a[i][j-1] > 0 and a[i][j-1] < c:
          k = c
        if i < w-1 and a[i+1][j] > 0 and a[i+1][j] < c:
          k = c
        if j < h-1 and a[i][j+1] > 0 and a[i][j+1] < c:
          k = c
        if k == c:
          a[i][j] = c
  if p:
    break
  else:
    c+=1

print(c-2)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

Submission status: Runtime Error

Solution code:
num_i, num_j = input().split()
num_i = int(num_i)
num_j = int(num_j)
inputs = [input() for i in range(num_i)]
x = []
for _ in inputs:
    for value in _:
        x.append(value)
x = np.array(x)
x = x.reshape(num_i, num_j)

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

Submission status: Runtime Error

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

# In[190]:


import numpy as np
import copy


# In[207]:


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


# In[224]:


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

#print(B)

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


# In[ ]:

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    # H, W = [int(x) for x in input().split()]
    H, W = map(int, [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()
        X_len = len(X)
        for j in range(X_len):
            if X[j] == "#":
                board[i][j] = 1

    num_board = np.array(board)
    height, width = num_board.shape[:2]
    count = 0
    while (np.sum(num_board) != height*width):
        num_board_ans = np.zeros((height, width))
        for i in range(height):
            for j in range(width):
                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:
# coding: utf-8

from collections import deque

h, w = [int(x) for x in input().split()]

i_mat = []

queue = deque()


for i in range(h):
    x = input()
    i_mat.append([0 if y == "#" else 99999 for y in list(x)])

    for (j, t) in enumerate(i_mat[-1]):
        if t == 0:
            queue.append((i, j))


while queue:
    index = queue.popleft()
    curr = i_mat[index[0]][index[1]]

    # ←
    if index[0]-1 >= 0 and i_mat[index[0]-1][index[1]] > curr + 1:
        i_mat[index[0]-1][index[1]] = curr + 1
        queue.append((index[0]-1, index[1]))

    # ↑
    if index[1]-1 >= 0 and i_mat[index[0]][index[1]-1] > curr + 1:
        i_mat[index[0]][index[1]-1] = curr + 1
        queue.append((index[0], index[1]-1))

    # →
    if index[0]+1 < w and i_mat[index[0]+1][index[1]] > curr + 1:
        i_mat[index[0]+1][index[1]] = curr + 1
        queue.append((index[0]+1, index[1]))

    # ↓
    if index[1]+1 < h and i_mat[index[0]][index[1]+1] > curr + 1:
        i_mat[index[0]][index[1]+1] = curr + 1
        queue.append((index[0], index[1]+1))

result = 0

for data in i_mat:
    if result < max(data):
        result = max(data)

print(result)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    b=list(input())
    a_list.append(b)
dp=[]
for i in range(h):
    dps=[]
    for j in range(w):
        dps.append(10**9)
    dp.append(dps)
def f(x,y):
    if dp[x][y]<10**9:
        return dp[x][y]
    else:
        if a_list[x][y]=='#':
            dp[x][y]=0
            return 0
        else:
            dp[x][y]=10**8
            if x>0:
                k0=f(x-1,y)+1
            else:
                k0=10**9
            if x<h-1:
                k1=f(x+1,y)+1
            else:
                k1=10**9
            if y>0:
                k2=f(x,y-1)+1
            else:
                k2=10**9
            if y<w-1:
                k3=f(x,y+1)+1
            else:
                k3=10**9
            m=min(k0,k1,k2,k3)
            dp[x][y]=m
            return m
answer=0
for i in range(h):
    for j in range(w):
        answer=max(answer,f(i,j))
print(answer)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W =map(int ,raw_input().split())
l =[]
for i in range(H):
    l.append(map(str ,raw_input().split()))
for i in range(H):
    l[i] =list(l[i][0])
for i in range(H):
    for j in range(W):
        if l[i][j] == '#':
            l[i][j] = 0
        else:
            l[i][j] = 10000
def D(i,j,l):
    s = 10000
    if i>0:
        if l[i-1][j]+1<s:
            s = l[i-1][j]+1
    if j>0:
        if l[i][j-1]+1<s:
            s = l[i][j-1]+1
    if i<H-1:
        if l[i+1][j]+1<s:
            s = l[i+1][j]+1
    if j<W-1:
        if l[i][j+1]+1<s:
            s = l[i][j+1]+1
    return s
Max = 0
while flag == 1:
    flag = 0
    Max = Max +1
    for i in range(H):
        for j in range(W):
            if l[i][j] == 10000:
                l[i][j] = D(i,j,l)
                if l[i][j] == 10000:
                    flag =1
print str(Max)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
kuro = []
siro = []
kyoris = []

def kyori(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])

for i in range(h):
    Ai = input()
    for j, Aij in enumerate(Ai):
        if Aij == "#":
            kuro.append((i, j))
        else:
            siro.append((i,j))
for si in siro:
    kyoris.append(min([kyori(si, ki) for ki in kuro]))

print(max(kyoris))

Submission status: Runtime Error

Solution code:

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

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([j, i])
            end += 1
HW = H * W
ans = 0
while (end < HW):
    nl = []
    for ll in l:
        if (0 < ll[0]):
            if (m[ll[1]][ll[0] - 1] == '.'):
                m[ll[1]][ll[0] - 1] = '#'
                end += 1
                nl.append([ll[1], ll[0] - 1])

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

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

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

print(ans)

Submission status: Runtime Error

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

black = list()
for i in range(H):
    A.append(list(input().strip()))
    for j in range(len(A[i])):
        if A[i][j] == '#':
            black.append((i, j))

T = [[0 for col in range(H)] for row in range(W)]

md = 0
for i in range(H):
    for j in range(W):
        dist = [abs(b[0] - i) + abs(b[1] - j) for b in black]
        T[i][j] = min(dist)
    md = max(md, max(T[i]))

print(md)

Submission status: Runtime Error

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

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

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

print(2)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import pprint

h,w = na()

a = []

for i in range(h):
  s = ns()
  b = []
  for j in s:
    if j == '#':
      b.append(1)
    if j == '.':
      b.append(0)
  a.append(b)

t = []
c = 2
while(True):
  p = True
  for i in range(w):
    for j in range(h):
      if a[i][j] == 0:
        p = False
        k = 1
        if i > 0 and a[i-1][j] > 0 and a[i-1][j] < c:
          k = c
        if j > 0 and a[i][j-1] > 0 and a[i][j-1] < c:
          k = c
        if i < w-1 and a[i+1][j] > 0 and a[i+1][j] < c:
          k = c
        if j < h-1 and a[i][j+1] > 0 and a[i][j+1] < c:
          k = c
        if k == c:
          a[i][j] = c
  if p:
    break
  else:
    c+=1

print(c-2)

Submission status: Runtime Error

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits



def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))

def update(bit,i, dp):
    bit[i] = dp
    return bit

def query(bit, i):
    lis = [bit[j] for j in range(i)]
    return max(lis)


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()

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

black = [[i, j] for i in range(H) for j in range(W) if a[i][j] == '#']
white = [[i, j] for i in range(H) for j in range(W) if a[i][j] == '.']

dis = []
for x in white:
    tmp = [abs(x[0] - y[0]) + abs(x[1] - y[1]) for y in black]
    dis.append(min(tmp))

print(max(dis))

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
L=[]
for i in range(h):
    L.append(list(input()))
dy_dx=[[0,1],[0,-1],[1,0],[-1,0]]
que=deque([])
for i in range(h):
    for j in range(w):
        if L[i][j]=="#":
            L[i][j]=0
        else:
            L[i][j]=-1
        if L[i][j]!=-1:
            que.append([i,j])
arg_j=0
cnt=0
MAX=0
while True:
    cnt+=1
    for j in range(h):
        for k in range(w):
            if L[j][k]==cnt-1:
                for i in range(4):
                    if 0<=j+dy_dx[i][0]<=h-1 and 0<=k+dy_dx[i][1]<=w-1:
                        if L[j+dy_dx[i][0]][k+dy_dx[i][1]]==-1:
                            L[j+dy_dx[i][0]][k+dy_dx[i][1]]=cnt
                            MAX=max(MAX,cnt)
    if cnt>=1001:
        break
    if MAX!=cnt:
        break
print(MAX)

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):
      if sum(a[i])!=0 or a[i][j]==1:
        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:
#!/usr/bin/env python
# coding: utf-8

# In[190]:


import numpy as np
import copy


# In[207]:


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


# In[216]:


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

#print(B)

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

Submission status: Runtime Error

Solution code:
import numpy as np
#black = #
#white = .

Input_1 = input().split()
H = int(Input_1[0])
W = int(Input_1[1])
A = []
for i in range(H):
    Input_A = input()
    Input_A = list(Input_A)
    Input_A = np.array(Input_A, str)
    A.append(Input_A)
A = np.array(A, str)
num = 0
while 1:
    x = []
    for i in range(H):
        for j in range(W):
            if i == 0:
                if j == 0:
                    if A[i+1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
                elif j == W-1:
                    if A[i][j-1] == '#' or A[i+1][j] == '#':
                        x.append([i,j])
                else:
                    if A[i][j-1] == '#' or A[i+1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
            elif i == H-1:
                if j == 0:
                    if A[i-1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
                elif j == W-1:
                    if A[i-1][j] == '#' or A[i][j-1] == '#':
                        x.append([i,j])
                else:
                    if A[i][j-1] == '#' or A[i-1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
            elif j == 0:
                if i == 0:
                    if A[i+1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
                elif i == H-1:
                    if A[i-1][j] == '#' or A[i][j+1] == '#':
                        x.append([i,j])
                else:
                    if A[i][j+1] == '#' or A[i+1][j] == '#' or A[i-1][j] == '#':
                        x.append([i,j])
            elif j == W-1:
                if i == 0:
                    if A[i+1][j] == '#' or A[i][j-1] == '#':
                        x.append([i,j])
                elif i == H-1:
                    if A[i-1][j] == '#' or A[i][j-1] == '#':
                        x.append([i,j])
                else:
                    if A[i][j-1] == '#' or A[i+1][j] == '#' or A[i-1][j] == '#':
                        x.append([i,j])
            else:
                if A[i-1][j] == '#' or A[i][j-1] == '#' or A[i+1][j] == '#' or A[i][j+1] == '#':
                    x.append([i,j])
    for i_j in x:
        A[i_j[0]][i_j[1]] = '#'
    num+=1
    key = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] == '.':
                key = 1
                break
    if key == 0:
        break
print(num)

Submission status: Runtime Error

Solution code:
import sys

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

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

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

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

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

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

Submission status: Runtime Error

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

A  = [['0'] * (W + 2)]

for _ in range(H):
    tmp = list(input())
    A = A + [['0'] + [str(int(x == '#')) for x in tmp] + ['0']]
A = A + [['0'] * (W + 2)]

#print(A)

import numpy as np
frame = np.array(A)
frame = np.reshape(frame, (H+2, W+2))
#print(frame)
#print("===================")

END_NUM = int(('1' * W + '0'), 2)
ans = 0

while True:
    # 縦方向のbit化
    bit_frame = []
    for a in frame:
        tmp = ''.join(a)
        bit_frame.append(int(tmp, 2))
    #print(bit_frame)
    
    # 終了チェック
    #print(END_NUM)
    if bit_frame.count(END_NUM) == len(bit_frame) - 2:
        break
    else:
        ans += 1

    
    # 横方向のbit化
    rot_frame = np.rot90(frame, k=1)
    #print(rot_frame)
    rot_bit_frame = []
    for a in rot_frame:
        tmp = ''.join(a)
        rot_bit_frame.append(int(tmp, 2))
    #print(rot_bit_frame)

    # 縦方向のOR
    next_bit_frame = [0]
    for i in range(1, len(bit_frame)-1):
        next_bit_frame.append( bit_frame[i-1] | bit_frame[i] | bit_frame[i+1] )
    next_bit_frame.append(0)
    #print(next_bit_frame)

    # 横方向のOR
    next_rot_bit_frame = [0]
    for i in range(1, len(rot_bit_frame)-1):
        next_rot_bit_frame.append( rot_bit_frame[i-1] | rot_bit_frame[i] | rot_bit_frame[i+1] )
    next_rot_bit_frame.append(0)
    #print(next_rot_bit_frame)

    # 横方向を回転
    next_rot_bit_frame = np.array([list(format(x, 'b').zfill(W+2)) for x in next_rot_bit_frame])
    #print("--")
    #print(next_rot_bit_frame )
    next_rot_bit_frame = np.rot90(next_rot_bit_frame, k=3)
    #print(next_rot_bit_frame )
    tmp_bit_frame = []
    for a in next_rot_bit_frame:
        tmp = ''.join(a)
        tmp_bit_frame.append(int(tmp, 2))
    next_rot_bit_frame = tmp_bit_frame[:]
    #print(next_bit_frame)
    #print(next_rot_bit_frame)
    next_frame = []
    for a, b in zip(next_bit_frame, next_rot_bit_frame):
        next_frame.append(a | b)
    #print(next_frame)
    
    frame = np.array([list(format(x, 'b').zfill(W+2)) for x in next_frame])
    #print(frame)

print(ans)

Submission status: Runtime Error

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


def solve(H: int, W: int, A: "List[str]"):
    holes = [[float('inf')] * W for _ in range(H)]
    for i,l in enumerate(A):
        for j, c in enumerate(l):
            if c == '#':
                holes[i][j] = 0

    for j in range(1, W):
        holes[0][j] = min(holes[0][j], holes[0][j-1] + 1)
    for i in range(1, H):
        holes[i][0] = min(holes[i][0], holes[i - 1][0] + 1)
    for i in range(1, H):
        for j in range(1, W):
            holes[i][j] = min(holes[i][j], holes[i-1][j] + 1, holes[i][j-1] + 1)

    ret = -float('inf')
    for j in range(W - 2, -1, -1):
        holes[H - 1][j] = min(holes[H - 1][j], holes[H - 1][j+1] + 1)
        ret = max(ret, holes[H - 1][j])
    for i in range(H - 2, -1, -1):
        holes[i][-1] = min(holes[i][-1], holes[i + 1][-1] + 1)
        ret = max(ret, holes[i][-1])
    for i in range(H - 2, -1, -1):
        for j in range(W - 2, -1, -1):
            holes[i][j] = min(holes[i][j], holes[i+1][j] + 1,  holes[i][j+1] + 1)
            ret = max(ret, holes[i][j])
    return ret


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
a = [['.' for j in range(h)] for i in range(h)]
black = []
for i in range(h):
    line = list(input())
    for j, c in enumerate(line):
        a[i][j] = c
        if c == '#':
            black.append([i,j])
ans = []
for i, line in enumerate(a):
    for j, c in enumerate(line):
        if c == '.':
            tem = 10**10
            for x, y in black:
                tem = min(tem, abs(x-i) + abs(y-j))
            ans.append(tem)
print(max(ans))

Submission status: Runtime Error

Solution code:
A = []

num_lines = int(input())
for i in range(num_lines):
    line = input()
    
    if(i==0):
        first = line.split(' ')
        H = first[0]
        W = first[1]
    
else:
    A.append(line)

 def CheckBlack(i,j):
    isBlack = False
    
    #north
    if (i - 1 > 0):
        if(A[i-1][j] == '#'):
            isBlack = True

    #south
    if(i + 1 < H):
        if(A[i+1][j] == '#'):
            isBlack = True
    
    #west
    if(j - 1 > 0):
        if(A[i][j -1] == '#'):
            isBlack = True

    #east
    if(j +1 < W):
        if(A[i][j + 1] == '#'):
            isBlack = True
            
    return isBlack

def CheckAllBlack(A):
    allblack = True

    flatA = [x for x in A for x in x]
    
    for i in flatA:
        if (i == '.'):
            allblack =  False
            break
        
    return allblack


isBlack = False
isStop = False
count = 0

while True:
    isStop = CheckAllBlack(A)
    if(isStop == True): break
    for i in range(H):
        for j in range(W):

            if(A[i][j]=="."):
                isBlack = CheckBlack(i,j)
                if(isBlack == True):
                    A[i][j] = "#"
    ShowA()

    count += 1
    

print(count)

Submission status: Runtime Error

Solution code:

number = input().split()

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

for i in range(number2):
    block = input()
print(2)

Submission status: Runtime Error

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

A  = [['0'] * (W + 2)]

for _ in range(H):
    tmp = list(input())
    A = A + [['0'] + [str(int(x == '#')) for x in tmp] + ['0']]
A = A + [['0'] * (W + 2)]

#print(A)

import numpy as np
frame = np.array(A)
frame = np.reshape(frame, (H+2, W+2))
#print(frame)
#print("===================")

END_NUM = int(('1' * W + '0'), 2)
ans = 0

while True:
    # 縦方向のbit化
    bit_frame = []
    for a in frame:
        tmp = ''.join(a)
        bit_frame.append(int(tmp, 2))
    #print(bit_frame)
    
    # 終了チェック
    #print(END_NUM)
    if bit_frame.count(END_NUM) == len(bit_frame) - 2:
        break
    else:
        ans += 1

    
    # 横方向のbit化
    rot_frame = np.rot90(frame, k=1, axes=(0, 1))
    #print(rot_frame)
    rot_bit_frame = []
    for a in rot_frame:
        tmp = ''.join(a)
        rot_bit_frame.append(int(tmp, 2))
    #print(rot_bit_frame)

    # 縦方向のOR
    next_bit_frame = [0]
    for i in range(1, len(bit_frame)-1):
        next_bit_frame.append( bit_frame[i-1] | bit_frame[i] | bit_frame[i+1] )
    next_bit_frame.append(0)
    #print(next_bit_frame)

    # 横方向のOR
    next_rot_bit_frame = [0]
    for i in range(1, len(rot_bit_frame)-1):
        next_rot_bit_frame.append( rot_bit_frame[i-1] | rot_bit_frame[i] | rot_bit_frame[i+1] )
    next_rot_bit_frame.append(0)
    #print(next_rot_bit_frame)

    # 横方向を回転
    next_rot_bit_frame = np.array([list(format(x, 'b').zfill(W+2)) for x in next_rot_bit_frame])
    #print("--")
    #print(next_rot_bit_frame )
    next_rot_bit_frame = np.rot90(next_rot_bit_frame, k=3, axes=(0, 1))
    #print(next_rot_bit_frame )
    tmp_bit_frame = []
    for a in next_rot_bit_frame:
        tmp = ''.join(a)
        tmp_bit_frame.append(int(tmp, 2))
    next_rot_bit_frame = tmp_bit_frame[:]
    #print(next_bit_frame)
    #print(next_rot_bit_frame)
    next_frame = []
    for a, b in zip(next_bit_frame, next_rot_bit_frame):
        next_frame.append(a | b)
    #print(next_frame)
    
    frame = np.array([list(format(x, 'b').zfill(W+2)) for x in next_frame])
    #print(frame)

print(ans)

Submission status: Runtime Error

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

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

lists = []

for i in range(number2):
    block = input()
    j = 0
    for i in range(number1):
        lists.append(block[j])
        j += 1

print(2)