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, input().split())
A = [[1 if s == '#' else 0 for s in input().rstrip()] for _ in range(H)]

count = 1
while True:
    for i in range(H):
        for j in range(W):
            if A[i][j] == count:
                A[i][j] += count
                if i-1 >= 0 and A[i-1][j] == 0:  # top
                    A[i-1][j] += 1+count
                if j-1 >= 0 and A[i][j-1] == 0:  # left
                    A[i][j-1] += 1+count
                if j+1 < W and A[i][j+1] == 0:  # right
                    A[i][j+1] += 1+count
                if i+1 < H and A[i+1][j] == 0:  # bottom
                    A[i+1][j] += 1+count
    if 0 not in [row[j] for i, row in enumerate(A) for j in range(len(A[i]))]:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
cnt = 0

while True:
  turns = []
  for i in range(h):
    for j in range(w):
      if A[i][j] == "#":
        turns.append((i+1, j))
        turns.append((i-1, j))
        turns.append((i, j+1))
        turns.append((i, j-1))
  t = set(turns)
  for turn in t:
    if 0 <= turn[0] < h and 0 <= turn[1] < w:
      A[turn[0]][turn[1]] = "#"
  turns.clear()
  flag = 0
  cnt += 1
  for i in range(h):
    for j in range(w):
      if A[i][j] == ".":
        flag = 1
        break
  if flag == 0:
    break

print(cnt)

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 = True

import copy

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

temp = copy.deepcopy(M)

while flg:
    count += 1

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

                f[h][w] = 1

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

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

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

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

        temp[h] = copy.copy(M[h])

    for h in range(H):
        flg = 0 in f[h]

        if flg == True:
            break

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


print(count)

Submission status: Wrong Answer

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

check = [[0,0], [1, 0], [-1, 0], [0, 1], [0, -1]]

grid = []
new_grid = []
final_grid = []
cnt = 0

for i in range (H):
    row = input ()
    grid.append (list (row))
    new_grid.append (list('.' * W))
    final_grid.append (list('#' * W))

while True:
    for i in range (H):
        for j in range (W):
            if grid [i][j] == '#':
                for k in range (5):
                    #print (new_grid)
                    try:
                        new_grid [i + check [k][0]] [j + check [k][1]]
                    except:
                        continue
                    else:
                        new_grid [i + check [k][0]] [j + check [k][1]] = '#'
                grid = new_grid                     
    if grid != final_grid:
        cnt += 1
        continue
    else:
        cnt += 1
        break

print (cnt)

Submission status: Wrong Answer

Solution code:
import copy

H, W = map(int, input().split())
A = []
count = 0
for i in range(H):
  x = input()
  A.append(x)
  count += x.count('.')

ans = 0
allblack = False
while not allblack:
  B = copy.deepcopy(A)
  if count > 0:
    ans += 1
  else:
    allblack = True
  for i in range(H):
    for j in range(W):
      if A[i][j] == '#':
        if i - 1 >= 0 and A[i - 1][j] == '.':
          str_list = list(B[i - 1])
          str_list[j] = '#'
          B[i - 1] = ''.join(str_list)
          count -= 1
        if j - 1 >= 0 and A[i][j - 1] == '.':
          str_list = list(B[i])
          str_list[j - 1] = '#'
          B[i] = ''.join(str_list)
          count -= 1
        if i + 1 < H and A[i + 1][j] == '.':
          str_list = list(B[i + 1])
          str_list[j] = '#'
          B[i + 1] = ''.join(str_list)
          count -= 1
        if j + 1 < W and A[i][j + 1] == '.':
          str_list = list(B[i])
          str_list[j + 1] = '#'
          B[i] = ''.join(str_list)
          count -= 1
        str_list = list(B[i])
        str_list[j] = '%'
        B[i] = ''.join(str_list)
  A = copy.deepcopy(B)
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 = True

import copy

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

while flg:
    count += 1

    temp = copy.deepcopy(M)

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

                f[h][w] = 1

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

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

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

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

    for h in range(H):
        flg = 0 in f[h]

        if flg == True:
            break

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


print(count)

Submission status: Wrong Answer

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

l=[]
for i in range(H):
  l.append(list(input()))

if H==1 and W==1:
  print(0)
  exit()

c=0
while True:

  f=True
  for i in range(H):
    if '.' in l[i]:
      f=False

  if f:
    break

  c+=1
  
  for i in range(H):
    for j in range(W):
      x=l[i][j]
      if x=='#':
        if i>0 and i<H-1 and j>0 and j<W-1:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i==0 and j==0:
          f1=True
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i==0 and j>0 and j<W-1:
          f1=True
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i==0 and j==W-1:
          f1=True
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i>0 and i<H-1 and j==0:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i>0 and i<H-1 and j==W-1:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if l[i+1][j]=='.':
            l[i+1][j]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i==H-1 and j==0:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if f1:
            l[i][j]='b'

        elif i==H-1 and j>0 and j<W-1:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if l[i][j+1]=='.':
            l[i][j+1]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
        elif i==H-1 and j==W-1:
          f1=True
          if l[i-1][j]=='.':
            l[i-1][j]='a'
            f1=False
          if l[i][j-1]=='.':
            l[i][j-1]='a'
            f1=False
          if f1:
            l[i][j]='b'
  
    # l[i]=list(''.join(l[i]).replace('a','#'))
    for j in range(W):
      if l[i][j]=='a':
        l[i][j]='#'

print(c)

Submission status: Wrong Answer

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

check = [[0,0], [1, 0], [-1, 0], [0, 1], [0, -1]]

grid = []
new_grid = []
final_grid = []
cnt = 0

for i in range (H):
    row = input ()
    grid.append (list (row))
    new_grid.append (list('.' * W))
    final_grid.append (list('#' * W))

while True:
    for i in range (H):
        for j in range (W):
            if grid [i][j] == '#':
                for k in range (5):
                    #print (new_grid)
                    try:
                        new_grid [i + check [k][0]] [j + check [k][1]]
                    except:
                        continue
                    else:
                        new_grid [i + check [k][0]] [j + check [k][1]] = '#'
                        print (new_grid)
                grid = new_grid                     
    if grid != final_grid:
        cnt += 1
        continue
    else:
        cnt += 1
        break

print (cnt)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
c_list = list()
for i in range(H):
  b_list = list(map(lambda x: x, input()))
  for w in range(W):
    if b_list[w] == '#':
      c_list.append([i, w])
ans = 0
if len(c_list) != 0:
  ans += 1
  for i in range(H+W):
    ll = c_list.copy()
    for c in ll:
      if not c[0]-1 < 0:
        c_list.append([c[0]-1, c[1]])
      if not c[0]+1 > W-1:
        c_list.append([c[0]+1, c[1]])
      if not c[1]-1 < 0:
        c_list.append([c[0], c[1]-1])
      if not c[1]+1 > W-1:
        c_list.append([c[0], c[1]+1])
    c_list = list(set(map(tuple, c_list)))
    if len(c_list) >= H*W:
      break;
    else:
      ans += 1
else:
  ans = 0
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 = True

import copy

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

while flg:
    count += 1

    temp = copy.deepcopy(M)

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

                f[h][w] = 1

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

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

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

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

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

        if flg == True:
            break

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


print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

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

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

counter = 0


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


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

tmpList = []

while(True):
    for i in range(H):
        for j in range(W):
            if data[i][j] == '#':
                tmpList.append((i, j))

    for pos in tmpList:
        enBlack(data, pos)

    tmpList = []

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

Submission status: Wrong Answer

Solution code:
from collections import deque
h, w = list(map(int, input().split()))
board = [list(input()) for i in range(h)]
q = deque()
a = 0
for i in range(h):
    for j in range(w):
        if board[i][j] == "#":
            q.append((i,j, 0))
        board[i][j] = False


dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans = 0
while q:
    i,j,cnt = q.popleft()
    if board[i][j]:
        continue
    board[i][j] = True
    ans = max(ans, cnt)
    a += 1
    if a == h*w:
        break
    for x, y in zip(dx,dy):
        if 0<=i+x<h and 0<=j+y<w and not board[i][j]:
            q.append((i+x, j+y, cnt+1))
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
t = list()
lst = [0] * (2*W)
t.extend(lst)

for i in range(H):
  i = input()
  j = list(i)
  t.extend(j)
  q = [0] * W
  t.extend(q)
z = [0] * W
t.extend(z)
 
r = 0
while True:
  for c in range(H*W*2+3*W):
    if t[c] == "#":
      pass
    if t[c] == 0:
      pass
    else:
      if t[c-1] == "#" or t[c+1] == "#" or t[c+2*W] == "#" or t[c-2*W] == "#":
        t[c] = "#"
      else:
        pass
  if t.count(".") == 0:
    break
  r += 1
print(r)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
from pprint import pprint

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

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

counter = 0


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


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

tmpList = []

while(True):
    for i in range(H):
        for j in range(W):
            if data[i][j] == '#':
                tmpList.append((i, j))

    for pos in tmpList:
        enBlack(data, pos)

    pprint(data)

    tmpList = []

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

Submission status: Wrong Answer

Solution code:
import copy

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

A_copy = copy.deepcopy(A)
cnt = 0
while True:
    for p in range(H):
        if '.' in A[p]:
            for i in range(H):
                for j in range(W):
                    if A[i][j] == '.':
                        if i != 0:
                            A_copy[i-1][j] = '#'
                        if i != H-1:
                            A_copy[i+1][j] = '#'
                        if j != 0:
                            A_copy[i][j-1] = '#'
                        if j != W-1:
                            A_copy[i][j+1] = '#'
            A = copy.deepcopy(A_copy)
            cnt += 1
            break
    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))
A = [[1 if a=='#' else 0 for a in input()] for _ in range(H)]

blacks = [(h,w) for h in range(H) for w in range(W) if A[h][w]==1]
whites = set([(h,w) for h in range(H) for w in range(W) if A[h][w]==0])


ans = 0
while whites:
  ans += 1
  for h,w in blacks:
    for x in range(ans):
      whites.discard((h+x, w+ans-x))
      whites.discard((h-x, w+ans-x))
      whites.discard((h+x, w-ans+x))
      whites.discard((h-x, w-ans+x))

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
c_list = list()
for i in range(H):
  b_list = list(map(lambda x: x, input()))
  for w in range(W):
    if b_list[w] == '#':
      c_list.append([i, w])
ans = 1
for i in range(H+W):
  ll = c_list.copy()
  for c in ll:
    if not c[0]-1 < 0:
      c_list.append([c[0]-1, c[1]])
    if not c[0]+1 > W-1:
      c_list.append([c[0]+1, c[1]])
    if not c[1]-1 < 0:
      c_list.append([c[0], c[1]-1])
    if not c[1]+1 > W-1:
      c_list.append([c[0], c[1]+1])
    c_list = list(set(map(tuple, c_list)))
  if len(c_list) >= H*W:
    break;
  else:
    ans += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

def check_all_black(M):
    for i in range(1, len(M) - 1):
        for j in range(1, len(M[i]) - 1):
            if M[i][j] == ".":
                return False
    
    return True

H, W = map(int, input().split())
A = ["." * (W + 2)]
for h in range(H):
    A.append(input())
    A[-1] = "." + A[-1] + "."
A.append("." * (W + 2))
for h in range(len(A)):
    A[h] = list(A[h])

print(A)

cnt = 0
while(1):
    if check_all_black(A) == True:
        print(cnt)
        break
    else:
        A_new = []
        for h in range(0, H + 2):    
            A_new.append(list("." * (W + 2)))
        for h in range(1, H + 1):
            for w in range(1, W + 1):
                if A[h][w] == "#" or \
                   A[h - 1][w] == "#" or \
                   A[h + 1][w] == "#" or \
                   A[h][w - 1] == "#" or \
                   A[h][w + 1] == "#":
                   A_new[h][w] = "#"
                else:
                    A_new[h][w] = "."
            # print(A_new[h])
    
    for h in range(0, H + 2):
        A[h] = copy.copy(A_new[h])
    cnt += 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 = True

import copy

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

while flg:
    count += 1

    temp = copy.deepcopy(M)

    for h in range(H):
        for w in range(W):
            if f[h][w] == 1 or temp[h][w] == '.':
                continue

            else:
                f[h][w] = 1

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

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

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

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

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

        if flg == True:
            break

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


print(count)

Submission status: Wrong Answer

Solution code:
import copy
H, W = [int(i) for i in input().split()]
M = []
V = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
	chars = []
	for j,c in enumerate(input()):
		chars.append(c)
		if c == '#':
			V[i][j] = 0
	M.append(chars)
move = [[1,0], [-1,0], [0,1],[0,-1]]

s = 0


roop = 0
cnt = 0
while (cnt!=H*W):
	for i in range(H):
		for j in range(W):
			if V[i][j] == roop:
				for di,dj in move:
					ni = i+di
					nj = j+dj
					if (ni>=0 and ni < H and nj>=0 and nj<W):
						if V[ni][nj] == -1:
							V[ni][nj]=roop+1
	cnt = 0
	for i in range(H):
		for j in range(W):
			if (V[i][j]!=-1):
				cnt += 1
  
	roop += 1
print (roop)

Submission status: Wrong Answer

Solution code:
def g(field,x,y,h,w,ans):
     cnt = 1
     flag = h+w+1
     while cnt < flag:
          for i in range(0,cnt+1):
               j = cnt - i
               if i == 0:
                    search = [[x,y+j],[x,y-j]]
               elif j == 0:
                    search = [[x+i,y],[x-i,y]]
               else:
                    search = [[x+i,y+j],[x-i,y+j],[x+i,y-j],[x-i,y-j]]
               for p in search:
                    if (1<=p[0]) and (p[0]<=w) and (1<=p[1]) and (p[1]<=h):
                         if field[p[1]][p[0]] == "#":
                              return cnt
                         if ans[p[1]-1][p[0]-1] != "#":
                              flag == min(flag,cnt + ans[p[1]-1][p[0]-1])
          cnt += 1
     return flag


def f():
     answer = -1
     h,w = map(int,input().split())
     field = [["!"]*w ]
     for i in range(h):
          field.append(["!"]+list(input())+["!"])
     field.append(["!"]*w)
     ans = [["#"]*w for i in range(h)]
     for i in range(1,h+1):
          for j in range(1,w+1):
               if field[i][j] == "#":
                    ans[i-1][j-1] = 0
               elif field[i][j] == ".":
                    ans[i-1][j-1] = g(field,j,i,h,w,ans)
                    answer = max(answer,ans[i-1][j-1])
     print(answer)
     return
f()

Submission status: Wrong Answer

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

data = []

for a in range(h):
  data.append(raw_input())

maxlenh0 = [99999999]*w
maxlenhh = [99999999]*w
maxlenw0 = [99999999]*h
maxlenww = [99999999]*h

# think (x+y,x-y) and convert to maxlen(
for a in range(h):
  for b in range(w):
    if data[a][b] == "#":
      x = a+b
      y = a-b
      for c in range(w):
        # (c,0) -> (c,c)
        if maxlenh0[c] > max( abs(x-c), abs(y-c) ): maxlenh0[c] = max( abs(x-c), abs(y-c) )   # (c,0)
        # (c,h-1) -> (c+h-1,c-h+1)
        if maxlenhh[c] > max( abs(x- (c+h-1) ), abs(y- (c-h+1) ) ): maxlenhh[c] = max( abs(x- (c+h-1) ), abs(y- (c-h+1) ) )   # (c,h-1)

      for c in range(h):
        # (0,c) -> (c,-c)
        if maxlenw0[c] > max( abs(x-c), abs(y+c) ): maxlenw0[c] = max( abs(x-c), abs(y-c) )   # (0,c)
        # (w-1,c) -> (w-1+c,w-1-c)
        if maxlenww[c] > max( abs(x-(w-1+c)), abs(y-(w-1-c)) ): maxlenww[c] = max( abs(x-(w-1+c)), abs(y-(w-1-c)) )   # (c,h-1)

print max(maxlenh0 + maxlenhh + maxlenw0 + maxlenww)

Submission status: Wrong Answer

Solution code:
import copy

h, w = map(int, input().split())
a = []
for i in range(h):
    s = str(input())
    a.append([])
    for x in s:
        if x == '.':
            a[i].append(1)
        else:
            a[i].append(0)

ans = 0

while True:
    _a = copy.deepcopy(a)
    for _h in range(h):
        if 1 in a[_h]:
            for _w in range(w):
                if a[_h][_w] == 0:
                    _a[_h][max(0,_w-1)] = 0
                    _a[_h][min(w-1,_w+1)] = 0
                    _a[max(0,_h-1)][_w] = 0
                    _a[min(h-1,_h+1)][_w] = 0
    ans += 1
    a = copy.deepcopy(_a)
    cnt = sum([sum(x) for x in a])
    if cnt == 0:
        print(ans)
        break

Submission status: Wrong Answer

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


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

max_min_dist = 0
for white in white_list:
    min_dist = 10 ** 7
    for black in black_list:
        min_dist = min(min_dist, abs(white[0] - black[0]) + abs(white[1] - black[1]))
    if min_dist == 1:
        break

    max_min_dist = max(max_min_dist, min_dist)
print(max_min_dist)

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)]

black_list = set()
new_black_list = set()
for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            black_list.add((i, j))
            new_black_list.add((i, j))
      
c = 0
while True:
    c += 1
    
    lll = list(new_black_list)
    new_black_list = set()
    for x, y in lll:
        if x - 1 >= 0:
            black_list.add((x - 1, y))
            new_black_list.add((x - 1, y))
        if x + 1 < h:
            black_list.add((x + 1, y))
            new_black_list.add((x + 1, y))
        if y- 1 >= 0:
            black_list.add((x, y - 1))
            new_black_list.add((x, y - 1))
        if y + 1 < w:
            black_list.add((x, y + 1))
            new_black_list.add((x, y + 1))
            
    if h * w == len(black_list):
        break
        
print(c)

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 = True

import copy

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

while flg:
    count += 1

    temp = copy.deepcopy(M)

    for h in range(H):
        for w in range(W):
            if f[h][w] == 1 or temp[h][w] == '.':
                continue

            else:
                f[h][w] = 1

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

                    elif i == 1:
                        if h == H - 1:
                            continue
                        M[h + 1][w] = '#'

                    elif i == 2:
                        if w == 0:
                            continue
                        M[h][w - 1] = '#'

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

    flg = True

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

        if flg == True:
            break

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


print(count)

Submission status: Wrong Answer

Solution code:
import copy

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

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

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

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

print(cnt)

Submission status: Wrong Answer

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

string_list=[input() for i in range(h)]

string_dict = {}


for i, s in enumerate(string_list):
    for j, c in enumerate(list(s)):
        if c == '#':
            string_dict[(i, j)] = ('#', 0)
        else:
            string_dict[(i, j)] = ('.', 0)


def check_set_black(i, j, h, w, count):
    if 0 <= i < h and 0 <= j < w:
        string_dict[(i, j)] = ('#', count)
    return string_dict


count = 1
while 1:
    for k, v in string_dict.items():
        i = k[0]
        j = k[1]
        tmp_count = int(v[1])
        if v[0] == '#' and tmp_count + 1 == count:
            string_dict = check_set_black(i+1, j, h, w, count)
            string_dict = check_set_black(i-1, j, h, w, count)
            string_dict = check_set_black(i, j + 1, h, w, count)
            string_dict = check_set_black(i, j - 1, h, w, count)

    if all(x[0] == '#' for x in string_dict.values()):
        break

    count += 1


print(count)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
t = list()
lst = [0] * (2*W)
t.extend(lst)
 
for i in range(H):
  i = input()
  j = list(i)
  t.extend(j)
  q = [0] * W
  t.extend(q)
z = [0] * W
t.extend(z)
 
r = 0
while True:
  for c in range(H*W*2+3*W):
    if t[c] == "#":
      pass
    if t[c] == 0:
      pass
    else:
      if t[c-1] == "#" or t[c+1] == "#" or t[c+2*W] == "#" or t[c-2*W] == "#":
        t[c] = "#"
      else:
        pass
  r += 1
  if t.count(".") == 0:
    break
print(r)

Submission status: Wrong Answer

Solution code:
import copy
height, width = map(int, input().split())
masu = []
count = 0
flag = 1
for i in range(height):
  masu.append(list(input()))
check = copy.deepcopy(masu)
while flag == 1:
  flag = 0
  for i in range(width):
    for n in range(height):
      if check[n][i] == '#':
        if n-1 > -1:
          masu[n-1][i] = '#'
        if i-1 > -1:
          masu[n][i-1] = '#'
        if i+1 < width:
          masu[n][i+1] = '#'
        if n+1 < height:
          masu[n+1][i] = '#'
  count+=1
  for i in masu:
    for n in i:
      if n == '.':
        flag = 1
        check = copy.deepcopy(masu)
        break
    else:
      continue
    break
print(count)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
e = [list(map(str,list(input())))for c in range(H)]
a = []
d = 0
for c in range(H):
  for i in range(W):
    if i =="#":
      a.append(int(c+i))
for x in range(len(a)):
  for y in range(H*W):
    if abs(a[x]-y) > d:
      d = abs(a[x]-y)
print(d)

Submission status: Wrong Answer

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



H,W = map(int,input().split())
A = []
dist=[[inf for i in range(W+2)] for j in range(H+2)]
def binary_search(l,r):
    while abs(r-l) >1:
        mid = (l+r)//2
        if solve(mid):#判定のとこは別で
            r = mid
        else:
            l = mid
    return r
for i in range(H):
    a = list(input())
    A.append(a)
    for j in range(W):
        if a[j] == "#":
            dist[i+1][j+1] = 0
while True:
        flag = 0
        for h in range(1,H+1):
            for w in range(1,W+1):
                if dist[h][w] >= inf:
                    dist[h][w] =min(dist[h-1][w]+1,dist[h+1][w]+1,dist[h][w+1]+1,dist[h][w-1]+1)
                    flag = 1
        if flag == 0:
            break
ans = 0
for h in range(1,H+1):
    for w in range(1,W+1):
        ans = max(ans,dist[h][w])
print(ans)