Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

3



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


Sample output:
2

Submission status: Wrong Answer

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

A=[ [] for i in range(H) ]
for i in range(H):
	a=raw_input()
	for x in a:
		if x==".":
			A[i].append(0)
		else:
			A[i].append(float("inf"))


D=[ (-1,0),(1,0),(0,1),(0,-1)]


flag=False
cnt=1
for h in range(H):
	for w in range(W):
		u=A[h][w]	#point
		if u==float("inf"):
			for dx,dy in D:
				if 0<=h+dx<H and 0<=w+dy<W and A[h+dx][w+dy]==0:
					flag=True
					A[h+dx][w+dy]=cnt
else:
	if flag!=True:
		cnt-=1
		print cnt
		quit()



for _ in range(100):
	flag=False
	cnt+=1
	for h in range(H):
		for w in range(W):
			u=A[h][w]	#point
			if u==cnt-1:
				for dx,dy in D:
					if 0<=h+dx<H and 0<=w+dy<W and A[h+dx][w+dy]==0:
						flag=True
						A[h+dx][w+dy]=cnt
	else:
		if flag!=True:
			cnt-=1
			print cnt
			quit()

Submission status: Wrong Answer

Solution code:
H, W = [int(c) for c in input().split()]
A = [[c=='#' for c in input()] for row in range(H)]

black = []
white = []
for irow in range(H):
    for icol in range(W):
        if A[irow][icol]: black.append((irow,icol))
        else: white.append((irow,icol))


dmax=0
for bx, by in black:
    dmin=1000000
    for wx, wy in white:
        d = abs(bx-wx)+abs(by-wy)
        if d<dmin: dmin=d
    if dmin>dmax:dmax=dmin

print(dmin)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split())
A = tuple(input() for _ in range(H))

INF = H * W

dp = np.full((H, W), INF)

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

for i in range(1, H):
	dp[i, :] = np.minimum(dp[i, :], dp[i-1, :] + 1)
for i in range(0, H-1)[::-1]:
	dp[i, :] = np.minimum(dp[i, :], dp[i+1, :] + 1)
for j in range(1, W):
	dp[:, j] = np.minimum(dp[:, j], dp[:, j-1] + 1)
for j in range(0, W-1)[::-1]:
	dp[:, j] = np.minimum(dp[:, j], dp[:, j+1] + 1)

print(np.max(dp))

Submission status: Wrong Answer

Solution code:
import queue
h, w = [int(i) for i in input().split()]
c = [[10000 for _ in range(w)] for _ in range(h)]
for i in range(h):
    _a = input()
    for j in range(len(_a)):
        if _a[j] == "#":
            c[i][j] = 0
#右方向
def right():
    for i in range(len(c)):
        for j in range(1, len(c[i])):
            c[i][j] = min(c[i][j], c[i][j-1]+1)

def left():
    for i in reversed(range(len(c))):
        for j in range(len(c[i])-1):
            c[i][j] = min(c[i][j], c[i][j+1]+1)

def up():
    for i in range(1, len(c)):
        for j in range(len(c[i])):
            c[i][j] = min(c[i][j], c[i - 1][j]+1)

def down():
    for i in reversed(range(len(c)-1)):
        for j in range(len(c[i])):
            c[i][j] = min(c[i][j], c[i + 1][j]+1)

right()
left()
down()
up()
_max = 0
for i in range(len(c)):
    # print(c[i])
    _max = max(_max, max(c[i]))
print(_max)

Submission status: Wrong Answer

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

h, w = map(int, input().split())
l = [list(input().strip()) for _ in range(h)]

def copy(ll):
    nl = [[None] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            nl[i][j] = ll[i][j]
    return nl

nl = copy(l)

c = 0
while True:
    c += 1
    for i in range(h):
        for j in range(w):
            if l[i][j] == "#":
                if i - 1 >= 0:
                    nl[i - 1][j] = "#"
                if i + 1 < h:
                    nl[i + 1][j] = "#"
                if j - 1 >= 0:
                    nl[i][j - 1] = "#"
                if j + 1 < w:
                    nl[i][j + 1] = "#"

    l = copy(nl)
    
    f = True
    for i in range(h):
        p = set(l[i])
        if "." in p:
            f = False
            break

    if f:
        break
        
print(c)

Submission status: Wrong Answer

Solution code:
import copy

h, w = list(map(int, input().split()))
data = []
for _ in range(h):
  data.append(list(map(lambda x: 1 if x == '#' else 0 , list(input()))))
count = 0
while True:
  tmp = copy.deepcopy(data)
  for i in range(h):
    for j in range(w):
      if data[i][j] == 1:
        if j > 0: 
          tmp[i][j-1] = 1
        if j < w-1:
          tmp[i][j+1] = 1
        if i > 0:
          tmp[i-1][j] = 1
        if i < h-1:
          tmp[i+1][j] = 1
  count += 1
  result = sum(map(sum, tmp))
  if result == h * w:
    break
  data = tmp
print(count)

Submission status: Wrong Answer

Solution code:
H,W=(int(x) for x in input().split())
yoko=[input() for _ in range(H)]
map=[[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        if yoko[h][w]=='#':
            map[h][w]=1
i=2
while i<3000:
    for h in range(H):
        for w in range(W):
            if map[h][w]==i-1:
                if h-1>=0:
                    if map[h-1][w]==0:
                        map[h-1][w]=i
                if w-1>=0:
                    if map[h][w-1]==0:
                        map[h][w-1]=i
                if h+1<H:
                    if map[h+1][w]==0:
                        map[h+1][w]=i
                if w+1<W:
                    if map[h][w+1]==0:
                        map[h][w+1]=i
    k=0
    for h in range(H):
        for w in range(W):
            if map[h][w]==0:
                k=k+1
    if k==0:
        print(i-1)
        break
    i=i+1

Submission status: Wrong Answer

Solution code:

H,W=[int(thing) for thing in list(str(input()).split(" "))]
banmen_list=[]
for h in range(H):
    banmen_list.append(list(str(input())))

def sousa(banmen,kaisu):
    rbanmen_list=banmen
    T=False
    for i in range(H):
        for j in range(W):
            if banmen[i][j]=="#":
                osen = [(i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)]
                for y,x in osen:
                    if x<0 or y<0:
                        continue
                    if x>H-1 or y>W-1:
                        continue
                    if rbanmen_list[x][y]=="#":
                        continue
                    if banmen[x][y] == "#":
                        continue
                    rbanmen_list[x][y]="#"
                    T=True
    if T==False:
        if kaisu==0:
            print(kaisu)
        else:
            print(kaisu+1)
        return
    else:
        kaisu=kaisu+1
        sousa(rbanmen_list,kaisu)
sousa(banmen_list,0)

Submission status: Wrong Answer

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


def main(inputs):
    h, w = map(int, next(inputs).split())
    mass = [ next(inputs) for _ in range(h) ]

    print(max([
        find_black(mass, 0, 0),
        find_black(mass, 0, len(mass[0])-1),
        find_black(mass, len(mass)-1, 0),
        find_black(mass, len(mass)-1, len(mass[0])-1),
    ]))

    pass


def find_black(mass, h, w):
    done = [ [ False ] * len(mass[0]) for _ in mass ]
    
    q = deque()
    q.append((h, w, 0))
    while len(q):
        h, w, d = q.popleft()
        if mass[h][w] == '#':
            return d
        done[h][w] = True
        if h-1 >= 0 and not done[h-1][w]:
            q.append((h-1, w, d+1))
            pass
        if h+1 < len(mass) and not done[h+1][w]:
            q.append((h+1, w, d+1))
            pass
        if w-1 >= 0 and not done[h][w-1]:
            q.append((h, w-1, d+1))
            pass
        if w+1 < len(mass[0]) and not done[h][w+1]:
            q.append((h, w+1, d+1))
            pass
        pass
    pass

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


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

Submission status: Wrong Answer

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

H, W = map(int, input().split())
A_array = [input()[:-1] for s in range(H)]

ans_array = [[1000] * W for i in range(H)]
# print(ans_array)

for i, A in enumerate(A_array):
    black_index = [i for i, x in enumerate(A) if x == "#"]
    # print(black_index)
    for black in black_index:
        ans_array = [[
            min(ans_array[h][w],
                abs(h - i) + abs(w - black)) for w in range(W)
        ] for h in range(H)]
print(max([max(ans_array[i]) for i in range(H)]))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import copy

H, W = list(map(int, input().split()))
a = [["#"] * (W + 2)]
for i in range(H):
    a.append(["#"] + list(input()) + ["#"])
a.append(["#"] * (W + 2))

print(a)
b = [[]]
ans = 0
while(a != b):
    b = copy.deepcopy(a)
    ans += 1
    for i in range(H):
        for j in range(W):
            if b[i + 1][j + 1] == "#":
                a[i][j + 1] = "#"
                a[i + 2][j + 1] = "#"
                a[i + 1][j] = "#"
                a[i + 1][j + 2] = "#"
    print(a)
    print(b)

print(ans - 1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import numpy as np
h, w = map(int, input().split())
l = []
for i in range(h):
    l.append(list(input()))
l = np.array(l)
ans = 0
while ans < 10:
    l2 = l[:, :]
    for i in range(h):
        for j in range(w):
            if l[i, j] == "#":
                if 0 < i < h - 1:
                    if 0 < j < w - 1:
                        l2[i, j+1] = "#"
                        l2[i, j-1] = "#"
                        l2[i+1, j] = "#"
                        l2[i-1, j] = "#"
                    else:
                        l2[i+1, j] = "#"
                        l2[i-1, j] = "#"
                elif 0 < j < w - 1:
                    l2[i, j+1] = "#"
                    l2[i, j-1] = "#"
    ans += 1
    l = l2[:, :]
    if np.unique(l).shape[0] == 1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split(" "))
A = [[int(s == '#') for s in input()] for _ in range(H)]

import heapq
pque = []
heapq.heapify(pque)
ans = 0

for h in range(H):
    for w in range(W):
        if A[h][w] == 1:
            for p in ([h-1, w], [h+1, w], [h, w-1], [h, w+1]):
                if p[0] >= H or p[0] < 0 or p[1] >= W or p[1] < 0:
                    continue
                if A[p[0]][p[1]] == 0:
                    heapq.heappush(pque, [1] + p)
                    A[p[0]][p[1]] = 1
        
while len(pque) > 0:
    item = heapq.heappop(pque)
    ans = item[0]
    h, w = item[1:]
    if A[h][w] == 1:
        for p in ([h-1, w], [h+1, w], [h, w-1], [h, w+1]):
                if p[0] >= H or p[0] < 0 or p[1] >= W or p[1] < 0:
                    continue
                if A[p[0]][p[1]] == 0:
                    heapq.heappush(pque, [item[0] + 1] + p)
                    A[p[0]][p[1]] = 1

Submission status: Wrong Answer

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

M = {};

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


#print(M)

count = 0

#flg = False

import copy

while True:
    #flg = False

    temp = copy.deepcopy(M)

    count += 1

    for h in range(H):
        for w in range(W):
            if M[h][w] == '#' and temp[h][w] == "#":
                i = 0

                while i < 4:
                    try:
                        if i == 0:
                            M[h - 1][w] = '#'
                            i += 1

                        elif i == 1:
                            M[h + 1][w] = '#'
                            i += 1

                        elif i == 2:
                            M[h][w - 1] = '#'
                            i += 1

                        elif i == 3:
                            M[h][w + 1] = '#'
                            i += 1

                    except IndexError:
                        i += 1

                    except KeyError:
                        i += 1

    flg = True

    for h in range(H):
        for w in range(W):
            if M[h][w] == ".":
                flg = False
                break   

        if flg == False:
            break

    #print(M)

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

    #     print()

    if flg:
        break


print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split())
A = tuple(input() for _ in range(H))

INF = H * W

dp = np.full((H, W), INF)

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

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

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

print(dp.max())

Submission status: Wrong Answer

Solution code:
import copy

def check(a, h, w, i, j):
    if a[i][j] == '#': return True
    if i != 0 and a[i-1][j] == '#': return True
    if j != 0 and a[i][j-1] == '#': return True
    if i < h-1 and a[i+1][j] == '#': return True
    if j < w-1 and a[i][j+1] == '#': return True
    return False

def f(a, h, w):
    count = 0
    now = a
    while True:
        count += 1
        nex = [['.' for i in range(w)] for j in range(h)]
        end = True
        for i in range(h):
            for j in range(w):
                if check(now, h, w, i, j): nex[i][j] = '#'
                else: end = False
        if end == True: break
        now = copy.deepcopy(nex)
    return count


h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

print(f(a, h, w))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[24]:

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


# In[25]:

"""
print(masu)
bin_masu = np.zeros((H, W))
masu = np.array(masu)
bin_masu[masu == '#'] = 1
print(bin_masu)
"""


# In[26]:

import numpy as np


# In[27]:

bin_masu = np.zeros((H, W))
masu = np.array(masu)
bin_masu[masu == '#'] = 1
#print(bin_masu.shape, masu.shape)
count = 0
#while True:
#print(bin_masu)
for _ in range(3):
    if np.all(bin_masu == 1):
        break
    tmp_masu = np.copy(bin_masu)
    #print(tmp_masu)
    tmp_masu[0:H-1] += bin_masu[1:H]
    #print(tmp_masu)
    tmp_masu[1:H] += bin_masu[0:H-1]
    #print(tmp_masu)
    tmp_masu[:,0:W-1] += bin_masu[:,1:W]
    #print(tmp_masu)
    tmp_masu[:,1:W] += bin_masu[:, 0:W-1]
    #print(tmp_masu)
    tmp_masu[tmp_masu > 0] = 1
    #print(bin_masu)
    #print(tmp_masu)
    bin_masu = tmp_masu
    count += 1
    #print('a')
print(count)


# In[ ]:

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[["x"for i in range(w+2)]]
for i in range(h):s.append(["x"]+[i for i in input()]+["x"])
s.append(["x"for i in range(w+2)])
flag,f=True,0
while flag:
  flag=False
  for i in range(1,h+1):
    for j in range(1,w+1):
      if s[i][j]==".":
        if f==0:
          if s[i-1][j]=="#"or s[i+1][j]=="#"or s[i][j-1]=="#"or s[i-1][j]=="#":s[i][j]=1;flag=True
        elif s[i]:
          if s[i-1][j]==f or s[i+1][j]==f or s[i][j-1]==f or s[i-1][j]==f:s[i][j]=f+1;flag=True
  f+=1
print(f-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
H, W = map(int, input().split())
maze = [input()for _ in range(H)]


def bfs(blacks: list) -> int:
    ans = 0
    dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    queue = deque()
    for bx, by in blacks:
        queue.appendleft((bx, by, 0))
    reached = set()
    while queue:
        d = queue.pop()
        if ans < d[2]:
            ans = d[2]
        for a in dxdy:
            x = d[0] + a[0]
            y = d[1] + a[1]
            if (x, y) not in reached and 0 <= x < W and 0 <= y < H and maze[y][x] != '#':
                queue.appendleft((x, y, d[2] + 1))
                reached.add((x, y))
    return ans


b = []
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            b.append((i, j))
print(bfs(b))

Submission status: Wrong Answer

Solution code:
from collections import deque
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
cnt = h*w
t = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      q.append((i,j))
      a[i][j] = 0
      cnt -= 1
for _ in range(cnt):
  y,x = q.popleft()
  for dx,dy in d:
    if 0 <= x+dx < w and 0 <= y+dy < h and a[y+dy][x+dx] == ".":
      t = a[y][x] + 1
      a[y+dy][x+dx] = t
      q.append((y+dy,x+dx)) 
print(t)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	H, W = map(int, input().split(" "))
	A = []
	shiro = 0
	
	for _ in range(H):
		tmp = input()
		tmp = tmp[:-1]
		tmp = list(tmp)
		for i in tmp:
			if i == ".":
				shiro += 1
		A.append(tmp)

	#print(shiro)
	A2 = copy.deepcopy(A)
	trun = 0
	while True:
		trun += 1
		#print(shiro)
		for i in range(H):
			for j in range(W):
				if trun % 2 == 0:
					if A[i][j] == "#":
						if i < H-1 and A[i+1][j] == "." and A2[i+1][j] == ".":
							A2[i+1][j] = "#"
							shiro -= 1
						if i > 0 and A[i-1][j] == "." and A2[i-1][j] == ".":
							A2[i-1][j] = "#"
							shiro -= 1
						if j < W-1 and A[i][j+1] == "." and A2[i][j+1] == ".":
							A2[i][j+1] = "#"
							shiro -= 1
						if j > 0 and A[i][j-1] == "." and A2[i][j-1] == ".":
							A2[i][j-1] = "#"
							shiro -= 1
						#print(A2)
				else:
					if A2[i][j] == "#":
						if i < H-1 and A2[i+1][j] == "." and A[i+1][j] == ".":
							A[i+1][j] = "#"
							shiro -= 1
						if i > 0 and A2[i-1][j] == "." and A[i-1][j] == ".":
							A[i-1][j] = "#"
							shiro -= 1
						if j < W-1 and A2[i][j+1] == "." and A[i][j+1] == ".":
							A[i][j+1] = "#"
							shiro -= 1
						if j > 0 and A2[i][j-1] == "." and A[i][j-1] == ".":
							A[i][j-1] = "#"
							shiro -= 1
						#print(A)
				if shiro == 0:
					print(trun)
					sys.exit()

	print(trun)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
M = np.zeros((H, W))
mH = np.eye(H, k = 1) + np.eye(H, k = -1)
mW = np.eye(W, k = 1) + np.eye(W, k = -1)
for j in range(H):
    k = input()
    K = [k[i] == '#' for i in range(W)]
    M[j] += K
c = 0
for v in range(10):
    if np.min(M) > 0:
        break
    c += 1
    M += np.dot(mH, M) + np.dot(M, mW)
print(c)

Submission status: Wrong Answer

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


def main():
  height, width = map(int, input().split())
  max_value = height * width
  values = []
  queue = []
  result = 0

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])
    queue.extend((x, y, 1) for x, v in enumerate(values[-1]) if v == 0)

  print(0, flush=True)

Submission status: Wrong Answer

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

def f(x, y):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < H and 0 <= ny < W and A[nx][ny] == '.':
            A[nx][ny] = '1'
            
ans = 0
cnt = 1
while cnt != 0:
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                f(i, j)
                
    cnt = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] == '1':
                A[i][j] = '#'
            elif A[i][j] == '.':
                cnt += 1
    ans += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

import numpy as np


# In[13]:

bin_masu = np.zeros((H, W))
masu = np.array(masu)
bin_masu[masu == '#'] = 1
#print(bin_masu.shape, masu.shape)
count = 0
#while True:
#print(bin_masu)
for _ in range(3):
    if np.all(bin_masu == 1):
        break
    tmp_masu = np.copy(bin_masu)
    #print(tmp_masu)
    tmp_masu[0:H-1] += bin_masu[1:H]
    #print(tmp_masu)
    tmp_masu[1:H] += bin_masu[0:H-1]
    #print(tmp_masu)
    tmp_masu[:,0:W-1] += bin_masu[:,1:W]
    #print(tmp_masu)
    tmp_masu[:,1:W] += bin_masu[:, 0:W-1]
    #print(tmp_masu)
    tmp_masu[tmp_masu > 0] = 1
    #print(bin_masu)
    #print(tmp_masu)
    bin_masu = tmp_masu
    count += 1
    #print('a')
print(count)


# In[ ]:

Submission status: Wrong Answer

Solution code:
import numpy as np

def atcoder_input():
    H, W = (int(i) for i in input().split())
    _ = []
    for i in range(H):
        l = [j for j in input().split()]
        _.append(l)
    _ = np.array(_)

    A = np.zeros((H, W)).astype("int")

    for h in range(H):
        for w in range(W):
            if _[h][0][w]==".":
                A[h][w] = 0
            else:
                A[h][w] = 1
    return A, H, W

def main():
    A, H, W = atcoder_input()
    y_where = np.where(A==1)[0]
    x_where = np.where(A==1)[1]
    print(x_where)
    print(y_where)

    max_score = 0
    for i in range(H):
        for j in range(W):
            if(A[i,j]==0):
                score=np.min(np.abs(i - x_where) + np.abs(j - y_where))
                if score >= max_score:
                    max_score = score

    print(max_score)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

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

flag = False
count = 0

while not flag:
    st = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == ".":
                if j == w - 1:
                    if i == h - 1:
                        if a[i][j - 1] == "#" or a[i - 1][j] == "#":
                            st.append([i, j])
                    elif i == 0:
                        if a[i][j - 1] == "#" or a[i + 1][j] == "#":
                            st.append([i, j])
                    else:
                        if a[i][j - 1] == "#" or a[i + 1][j] == "#"or a[i - 1][j] == "#":
                            st.append([i, j])
                elif j == 0:
                    if i == h - 1:
                        if a[i][j + 1] == "#" or a[i - 1][j] == "#":
                            st.append([i, j])
                    elif i == 0:
                        if a[i][j + 1] == "#" or a[i + 1][j] == "#":
                            st.append([i, j])
                    else:
                        if a[i][j + 1] == "#" or a[i + 1][j] == "#" or a[i - 1][j] == "#":
                            st.append([i, j])
                else:
                    if i == h - 1:
                        if a[i][j + 1] == "#" or a[i][j - 1] == "#" or a[i - 1][j] == "#":
                            st.append([i, j])
                    elif i == 0:
                        if a[i][j + 1] == "#" or a[i][j - 1] == "#" or a[i + 1][j] == "#":
                            st.append([i, j])
                    else:
                        if a[i][j + 1] == "#" or a[i][j - 1] == "#" or a[i + 1][j] == "#" or a[i - 1][j] == "#":
                            st.append([i, j])
    for i in range(len(st)):
        a[st[i][0]][st[i][1]] = "#"
    count = count + 1
    flag = True
    for i in range(h):
        for j in range(w):
            if a[i][j] == ".":
                flag = False

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

nq=input().split()
H=int(nq[0])
W=int(nq[1])

b = []
w = []

for i in range(H):
    row = input()
    #print(row)
    for j in range(W):
        if row[j] == "#":
            b.append([i,j])
        else:
            w.append([i,j])

def dist(x,y):
    for p in range(1,H+W):
        for q in range(p+1):
            #print(p)
            #print(p-q)
            if ([y+(p-q),x+q] in b) or ( [y-(p-q),x-q] in b) or( [y+(p-q),x-q] in b) or ([y-(p-q),x+q] in b):
                return p

ans = -1
for c in w:
    y = c[0]
    x = c[1]
    d = dist(x,y)
    #print(d)
    if d>ans:
        ans=d

print(ans)

Submission status: Wrong Answer

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

M = {};

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


#print(M)

count = 0

#flg = False

while True:
    #flg = False

    count += 1

    for h in range(H):
        for w in range(W):
            if M[h][w] == '#':
                i = 0

                while i < 4:
                    try:
                        if i == 0:
                            M[h - 1][w] = '#'
                            i += 1

                        elif i == 1:
                            M[h + 1][w] = '#'
                            i += 1

                        elif i == 2:
                            M[h][w - 1] = '#'
                            i += 1

                        elif i == 3:
                            M[h][w + 1] = '#'
                            i += 1

                    except IndexError:
                        i += 1

                    except KeyError:
                        i += 1

    flg = True

    for h in range(H):
        for w in range(W):
            if M[h][w] == ".":
                flg = False
                break   

        if flg == False:
            break

    #print(M)

    if flg:
        break


print(count)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

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

while True:
    flag = True
    for i in range(h):
        for j in range(w):
            if a[i][j] == ".":
                flag = False

    if flag:
        break

    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                if i > 0:
                    a[i - 1][j] = "#"

                if i < h - 1:
                    a[i + 1][j] = "#"

                if j > 0:
                    a[i][j - 1] = "#"

                if j < w - 1:
                    a[i][j + 1] = "#"

    k += 1

print(k)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
count = 0
for i in range(h):
    x = list(input())
    a.append(x)
jud9e = [0]
while len(jud9e) != 0:
    judge = []
    jud9e = []
    for gyo, i in enumerate(a):
        for retsu, j in enumerate(i):
            if j == "#":
                judge.append([gyo, retsu])
            if j == ".":
                jud9e.append(1)
    for i in judge:
        try:
            a[i[0]-1][i[1]] = "#"
        except:
            pass
        try:
            a[i[0]][i[1]-1] = "#"
        except:
            pass
        try:
            a[i[0]][i[1]+1] = "#"
        except:
            pass
        try:
            a[i[0]+1][i[1]] = "#"
        except:
            pass
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
INF = 10**9
sys.setrecursionlimit(INF)
def rec(h, w):
    visited[h][w] = True
    if A[h][w] == '#':
        ans[h][w] = 0
        return
    else:
        u, d, l, r = INF, INF, INF, INF
        if h > 0:
            if visited[h-1][w] == False:
                rec(h-1, w)
            u = ans[h-1][w] + 1
        if h < H-1:
            if visited[h+1][w] == False:
                rec(h+1, w)
            d = ans[h+1][w] + 1
        if w > 0:
            if visited[h][w-1] == False:
                rec(h, w-1)
            l = ans[h][w-1] + 1
        if w < W-1:
            if visited[h][w+1] == False:
                rec(h, w+1)
            r = ans[h][w+1] + 1
        ans[h][w] = min([u, d, l, r])

H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
visited = [[False for w in range(W)] for h in range(H)]
ans = [[INF for w in range(W)] for h in range(H)]
rec(0, 0)
print(max([w for h in ans for w in h]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May  4 21:06:46 2019

@author: Owner
"""

from queue import Queue

H, W = map(int, input().split())
A = [[-1] * W for _ in range(H)]
q = Queue()
for i in range(H):
    b = input()
    for j in range(W):
        if b[j] == '#':
            q.put((i, j, 0))
            A[i][j] = 0
ans = -1
while not q.empty():
    i, j, k = q.get()
    for x, y in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni = i + x
        nj = j + y
        if ni < 0 or nj < 0 or ni >= H or nj >= W:
            continue
        if A[ni][nj] >= 0:
            continue
        ans = max(ans, k + 1)
        A[ni][nj] = k + 1
        q.put((ni, nj, k + 1))
print(ans)