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:
import copy

def input_nums():
    return [ int(i) for i in input().split(" ") ]

nums = input_nums()
H = nums[0]
W = nums[1]

li = []
for h in range(H):
    li.append(input())

result = []
x = 0
y = 0
for l in li:
    result.append(l)

cnts = 0
nexts = True
while(nexts):
    nexts = False
    y = 0
    for l in li:
        x = 0
        for s in l:
            if(s == "#"):
                # 上チェック
                if(y>=1):
                    str_list = list(result[y-1])
                    str_list[x] = "#"
                    result[y-1] = "".join(str_list)
                # 左チェック
                if(x>=1):
                    str_list = list(result[y])
                    str_list[x-1] = "#"
                    result[y] = "".join(str_list)
                # 右チェック
                if(x<W-1):
                    str_list = list(result[y])
                    str_list[x+1] = "#"
                    result[y] = "".join(str_list)
                # 下チェック
                if(y<H-1):
                    str_list = list(result[y+1])
                    str_list[x] = "#"
                    result[y+1] = "".join(str_list)
            x += 1
        y += 1
    # 白があったら次へ
    for r in result:
        if("." in r):
            nexts = True
            break
    cnts += 1
    li = copy.copy(result)

print(cnts)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(100000)

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

field = []
for _ in range(H):
    temp_field = []
    for s in input():
        if s == '.':
            temp_field.append(0)
        else:
            temp_field.append(1)
    field.append(temp_field)
  
dp = [[0] * W for _ in range(H)]

def rec(i, j, depth):
    if field[i][j] == 1:
        return 0
    
    if dp[i][j] != 0:
        return dp[i][j]
     
    if depth > H + W:
        return depth

    dp[i][j] = H + W
        
    min_dist = H + W
    if i > 0:
        min_dist = min(min_dist, rec(i-1, j, depth+1) + 1)
    if i < H - 1:
        min_dist = min(min_dist, rec(i+1, j, depth+1) + 1)
    if j > 0:
        min_dist = min(min_dist, rec(i, j-1, depth+1) + 1)
    if j < W - 1:
        min_dist = min(min_dist, rec(i, j+1, depth+1) + 1)
        
    dp[i][j] = min_dist
    
    return min_dist

for i in range(H):
    for j in range(W):
        rec(i, j, 0)

print(max([max(temp_dp) for temp_dp in dp]))

Submission status: Wrong Answer

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

for j in range(h):
    tmp=[i for i, x in enumerate(a[j]) if x == '#']
    [brack.append(k+1+j+1) for k in tmp]

brack=sorted(list(set(brack)))
brack.append(h+w+1)

b=1
ans=0
for i in brack:
    if i-b-1>ans:
        ans=i-b-1
    b=i

print(ans)

Submission status: Wrong Answer

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

def rev(i, j, ar):
    if ar[i][j] != '#':
        ar[i][j] = '#'
        return 1
    return 0

def rev_tmp(i, j, ar):
    if ar[i][j] == '.':
        ar[i][j] = '-'

def rev_arround(i, j, h, w, ar):
    count = 1
    if (i>0):
        count += rev(i-1, j, ar)
    if (j>0):
        count += rev(i, j-1, ar)

    if (i<h-1):
        rev_tmp(i+1, j, ar)
    if (j<w-1):
        rev_tmp(i, j+1, ar)
    return count

ar = []
for ih in range(h):
    ar.append(list(input()))


for times in range(100):
    count = 0
    for ih in range(h):
        for iw in range(w):
            c = ar[ih][iw]
            if (c == '#'):
                count += rev_arround(ih, iw, h, w, ar)
                
            elif (c == '-'):
                ar[ih][iw] = '#'
                count += 1

    if count == h*w:
        break
print(times+1)

Submission status: Wrong Answer

Solution code:
from collections import deque
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]]
for i in range(h):
    for j in range(w):
        if L[i][j]=="#":
            L[i][j]=0
        else:
            L[i][j]=10**9+7
for i in range(h):
    for j in range(w):
        if L[i][j]!=10**9+7:
            que=deque([[i,j]])
while len(que)>0:
    cur=que.popleft()
    for i in range(4):
        if 0<=cur[0]+dy_dx[i][0]<=h-1 and 0<=cur[1]+dy_dx[i][1]<=w-1:
            if L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]]==10**9+7:
                for j in range(4):
                    a=float("inf")
                    b=float("inf")
                    c=float("inf")
                    d=float("inf")
                    if 0<=cur[0]+dy_dx[i][0]-1<=h-1 and 0<=cur[1]+dy_dx[i][1]<=w-1:
                        a=L[cur[0]+dy_dx[i][0]-1][cur[1]+dy_dx[i][1]]+1
                    if 0<=cur[0]+dy_dx[i][0]+1<=h-1 and 0<=cur[1]+dy_dx[i][1]<=w-1:
                        b=L[cur[0]+dy_dx[i][0]+1][cur[1]+dy_dx[i][1]]+1
                    if 0<=cur[0]+dy_dx[i][0]<=h-1 and 0<=cur[1]+dy_dx[i][1]-1<=w-1:
                        c=L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]-1]+1
                    if 0<=cur[0]+dy_dx[i][0]<=h-1 and 0<=cur[1]+dy_dx[i][1]+1<=w-1:
                        d=L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]+1]+1
                    L[cur[0]+dy_dx[i][0]][cur[1]+dy_dx[i][1]]=min(a,b,c,d)
                    que.append([cur[0]+dy_dx[i][0],cur[1]+dy_dx[i][1]])
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,L[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
blacks_xy =[]
whites_xy =[]
for i in range(h):
    for j in range(w):
        if s[i][j] =="#":
            blacks_xy.append([i,j])
        else:
            whites_xy.append([i,j])

mx = 1
def dist(w,b):
    l = abs(w[0]-b[0])
    m = abs(w[1]-b[1])
    return l+m


for i in range(len(whites_xy)):
    mi =10**9
    for j in range(len(blacks_xy)):
        mi = min(mi,dist(whites_xy[i],blacks_xy[j]))
    mx = max(mx,mi)
print(mx)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str
h, w = na()
a = []
for i in range(h):
	a.append(list(ns()))
a=np.array(a)
b=np.array(np.where(a=="#")).T
w=np.array(np.where(a==".")).T
M=-1000
m_list=[]
for i in w:
	m=10000000
	for j in b:
		#print(abs(i-j).sum())
		m = min(abs(i-j).sum(),m)
	M = max(M,m)

print(M)

Submission status: Wrong Answer

Solution code:
H, W = [int(item) for item in input().split()]
arr = [list(input().rstrip()) for _ in range(H)]
count = sum([item.count('#') for item in arr])
ans = 0
xy = [[-1,0], [1,0], [0,-1], [0,1]]

def check(h, w):
  if(arr[h][w] == '#'):
    return 0
  
  for x, y in xy:
    hy = h + y
    wx = x + w
    if (hy >= 0) and (wx >= 0) and (hy < H) and (wx < W):
      if t_arr[hy][wx] == '#':
        arr[h][w] = '#'
        return 1
  return 0

while True:
  t_arr = [item[:] for item in arr]
  for h in range(H):
    for w in range(W):
      count += check(h, w)
  ans += 1
  if count >= H * W:
    break

print(ans)

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 True:
    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 = [["."] * (w + 2)]
for i in range(h):
    a.append(list("." + input() + "."))
a.append([-1] * (w + 2))

num = []
for i in range(h + 2):
    temp = [-float("inf")] * (w + 2)
    num.append(temp)

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

flag = True
count = 0
while flag == True:
    flag2 = True
    for i in range(h):
        for j in range(w):
            if num[i+1][j+1] == -float("inf"):
                flag2 = False
                break
        if flag2 == False:
            break
    else:
        flag = False
        break
    for i in range(h):
        for j in range(w):
            if num[i+1][j+1] == -float("inf"):
                if num[i][j+1] > count:
                    num_up = -float("inf")
                else:
                    num_up = num[i][j+1]
                if num[i+1][j] > count:
                    num_left = -float("inf")
                else:
                    num_left = num[i+1][j]
                num2 = max(num[i+2][j+1], num_up, num[i+1][j+2], num_left)
                num[i+1][j+1] = num2 + 1
    count += 1
print(max([max(num[i]) for i in range(h)]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3

import itertools


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


def div_ceil(a, b):
    return (a + b - 1) // b


def count_operations(h, w, stage):
    is_black = [[cell == "#" for cell in line] for line in stage]
    # down
    cont_down = 0
    for c in range(w):
        cand_cont_down = 0
        ctr = 0
        for r in range(h):
            if is_black[r][c]:
                cand_cont_down = max(ctr, cand_cont_down)
                ctr = 0
            else:
                ctr += 1
        cand_cont_down = max(ctr, cand_cont_down)
        cont_down = max(cont_down, cand_cont_down)
    # right
    cont_right = 0
    for r in range(h):
        cand_cont_right = 0
        ctr = 0
        for c in range(w):
            if is_black[r][c]:
                cand_cont_right = max(ctr, cand_cont_right)
                ctr = 0
            else:
                ctr += 1
        cand_cont_right = max(ctr, cand_cont_right)
        cont_right = max(cont_right, cand_cont_right)
    cont = max(cont_down, cont_right)
    res = div_ceil(cont, 2)
    return res


def main():
    h, w = (int(z) for z in input().split())
    stage = [input() for _ in range(h)]
    res = count_operations(h, w, stage)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
## 計算量が(10^6)^2あるから絶対TLEなるけど

from sys import stdin
import numpy as np
 
H, W = map(int,input().split())
board = [[int(c) for c in l.replace('#','1').replace('.','0').strip()] for l in stdin]
board = np.array(board)

cnt = 0
while True:
  if np.all(board):
    ans = cnt
    break
  else:
    new_board_u = np.roll(board, -1, axis=0)
    new_board_u[-1][:] = 0
    new_board_d = np.roll(board, 1, axis=0)
    new_board_d[0][:] = 0
    new_board_l = np.roll(board, -1, axis=1)
    new_board_l[:][-1] = 0
    new_board_r = np.roll(board, 1, axis=1)
    new_board_r[:][0] = 0
    new_board = board + new_board_u + new_board_d + new_board_l + new_board_r
    board = new_board >= 1
    cnt += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  dep, wid = map(int, input().split())
  a = []
  for i in range(dep):
    s = input()
    a.append([])
    for j in range(len(s)):
      a[i].append(s[j])
  
  result = 0
  while True:
    flg = 0
    for i in range(dep):
      for j in range(wid):
        if i > 0 and a[i-1][j] == "#" and a[i][j] == ".":
          a[i][j] = "#"
          flg = 1
        elif i < dep-1 and a[i+1][j] == "#" and a[i][j] == ".":
          a[i][j] = "#"
          flg = 1
        elif j > 0 and a[i][j-1] == "#" and a[i][j] == ".":
          a[i][j] = "#"
          flg = 1
        elif j < wid-1 and a[i][j+1] == "#" and a[i][j] == ".":
          a[i][j] = "#"
          flg = 1
    
    if(flg == 1):
      result += 1
    else:
      break
      
  print(result)
  
main()

Submission status: Wrong Answer

Solution code:
import copy
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a2=copy.deepcopy(a)
count=0
print(a2)
while True:
  pflag=True
  countflag=False
  for i in range(h):
    for j in range(w):
      if a[i][j]=="#":
        if i != 0:
          a2[i-1][j]="#"
        if i != h-1:
          a2[i+1][j]="#"
        if j !=0:
          a2[i][j-1]="#"
        if j !=w-1:
          a2[i][j+1]="#"
      else:
        pflag= False
        countflag=True
  if countflag==True: count+=1
  for i in range(h):
    for j in range(w):
      a[i][j]=a2[i][j]
  print(a)
  if pflag == True:
    break
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=1
while True:
  
  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'
  
        if 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'
  
        if 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'
  
        if 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'
  
        if 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'
  
        if 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'
  
        if 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'
  
        if 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'
  
        if 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'
  
  f=False
  for i in range(H):
    if 'a' not in l[i]:
      f=True
    else:
      l[i]=list(''.join(l[i]).replace('a','#'))

  if f:
    break

  c+=1

print(c)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
cells = [['.'] * W for _ in range(H)]
dist = [[9999] * W for _ in range(H)]
stack = []

for i in range(H):
    line = input()
    for j in range(W):
        s = line[j]
        if s == '#':
            stack.append((i, j))
            dist[i][j] = 0
            cells[i][j] = s


while len(stack) != 0:
    y, x = stack.pop(0)
    dist_count = dist[y][x] + 1
    if x < W - 1 and dist[y][x+1] == 9999:
        dist[y][x+1] = dist_count
        stack.append((y, x+1))
    if y < H - 1 and dist[y+1][x] == 9999:
        dist[y+1][x] = dist_count
        stack.append((y+1, x))
    if 0 < x and dist[y][x-1] == 9999:
        dist[y][x-1] = dist_count
        stack.append((y, x-1))
    if 0 < y and dist[y-1][x] == 9999:
        dist[y-1][x] = dist_count
        stack.append((y-1, x))

print(dist)
max_dist_count = 0
for i in range(H):
    max_dist_count = max(max_dist_count, max(dist[i]))
print(max_dist_count)

Submission status: Wrong Answer

Solution code:
H,W = (int(i) for i in input().split())
e = [list(input()) for i in range(H)]
result = 0
for i in range(H):
  result += e[i].count("#")
onon = 0
while result != H * W:
    for tate in range(H):
        for yoko in range(W):
            if yoko == 0 and tate == 0 and e[tate][yoko] == ".":
                if  e[tate + 1][yoko] == "#" or  e[tate][yoko+1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif yoko == 0 and tate == H - 1 and e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#"  or  e[tate][yoko+1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif yoko == W -1 and tate == H - 1 and e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#" or  e[tate][yoko - 1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif yoko == W - 1 and tate == 0 and e[tate][yoko] == ".":
                if e[tate + 1][yoko] == "#" or  e[tate][yoko - 1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif yoko == 0 and tate != 0 and tate != H - 1 and e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#" or  e[tate + 1][yoko] == "#" or  e[tate][yoko+1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif tate == 0 and yoko != W - 1 and yoko != 0 and e[tate][yoko] == ".":
                if e[tate + 1][yoko] == "#" or  e[tate][yoko-1] == "#" or  e[tate][yoko+1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif yoko == W - 1 and tate != 0 and tate != H - 1 and e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#" or  e[tate + 1][yoko] == "#" or  e[tate][yoko-1] == "#" :
                	e[tate][yoko] = "#"
                	result += 1
            elif tate == H - 1 and yoko != W - 1 and yoko != 0 and e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#" or  e[tate][yoko-1] == "#" or  e[tate][yoko+1] == "#":
                	e[tate][yoko] = "#"
                	result += 1
            elif  e[tate][yoko] == ".":
                if e[tate - 1][yoko] == "#" or  e[tate + 1][yoko] == "#" or  e[tate][yoko-1] == "#" or  e[tate][yoko+1] == "#":
                    e[tate][yoko] = "#"
                    result += 1
    onon += 1
print(onon)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

Q = []
cnt = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            Q.append([i, j])
            cnt += 1

DX = [-1, 1, 0, 0]
DY = [0, 0, -1, 1]
d = 0
# for _ in range(5):
while cnt < H*W:
    d += 1
    tmp = []
    #print("d->", d)
    # print(Q)
    # print(dist)
    # print(cnt)
    # print("-------")
    for x, y in Q:
        for dx, dy in zip(DX, DY):
            nx = x+dx
            ny = y+dy
            if 0 <= nx < H and 0 <= ny < W:
                if grid[nx][ny] == ".":
                    grid[nx][ny] = "#"
                    tmp.append([nx, ny])
                    cnt += 1
            else:
                continue
    Q = tmp
# print(dist)
print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
b, c = map(int, input().split())
K = np.zeros((b,c))
for i in range(b):
    s = input()
    #print(s)
    for j in range(c):
        if s[j] == "#" :
            K[i,j] =1
#print(K)
count = 0
while(1):
    count =count+1
    S = copy.deepcopy(K)
    for i in range(b):
        for j in range(c):
            if S[i,j] == 1:
                try:
                    K[i,j+1] =1
                    #print("{},{}変更".format(i,j+1))
                except:
                    pass
                try:
                    if j != 0:
                        K[i,j-1] =1
                        #print("{},{}変更".format(i,j-1))
                except:
                    pass
                try:
                    if i != 0:
                        K[i-1,j] =1
                        #print("{},{}変更".format(i-1,j))
                except:
                    pass
                try:
                    K[i+1,j] =1
                    #print("{},{}変更".format(i+1,j))
                except:
                    pass
    #print(K)
    if np.all(K>0):
        break
    

print(count)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A_arr = []
s_arr1 = []

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


n_list = [[1, 0], [-1, 0], [0, 1], [0, -1]]
count = 0

while 1:
    count += 1
    for i in range(len(s_arr1)):
        for n in range(4):
            tmp = [s_arr1[i][0] + n_list[n][0], s_arr1[i][1] + n_list[n][1]]
            if tmp[0] < 0 or tmp[0] >= H:
                pass
            elif tmp[1] < 0 or tmp[1] >= W:
                pass
            elif tmp in s_arr1:
                pass
            else:
                s_arr1.append(tmp)

    if len(s_arr1) == H*W:
        break

print(count)

Submission status: Wrong Answer

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

NM = M.copy()
s = 0
ans = 0

cnt = 0
while (cnt!=H*W):
  cnt = 0
  for i in range(H):
    for j in range(W):
      if M[i][j]=='#':
        cnt += 1
        for di,dj in move:
          ni = i+di
          nj = j+dj
          if (ni>=0 and ni < H and nj>=0 and nj<W):
            NM[ni][nj]='#'
  ans += 1
  M=NM.copy()
print (ans-1)

Submission status: Wrong Answer

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

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

def delblack(list):
    black2=[]
    for x in list:
        if x not in black2:
            black2.append(x)
    return(black2)

def adblack(list):
    ans=[]
    for x in list:
        ans.append(x)
        if x[0]-1>=0:
            ans.append([int(x[0]-1),int(x[1])])
        if x[1]+1<H:
                ans.append([int(x[0]),int(x[1]+1)])
        if x[0]+1<W:
            ans.append([int(x[0]+1),int(x[1])])
        if x[1]-1>=0:
            ans.append([int(x[0]),int(x[1]-1)])
    return(ans)

N=int(H*W)
for i in range(N):
    #print(i)
    black=adblack(black)
    black=delblack(black)
    if len(black)==N:
        print(i+1)
        break

Submission status: Wrong Answer

Solution code:
import copy

def input_nums():
    return [ int(i) for i in input().split(" ") ]

nums = input_nums()
H = nums[0]
W = nums[1]

li = []
for h in range(H):
    li.append(input())

result = []
x = 0
y = 0
for l in li:
    result.append(l)

cnts = 0
nexts = True
while(nexts):
    nexts = False
    y = 0
    for l in li:
        x = 0
        for s in l:
            if(s == "#"):
                # 上チェック
                if(y>=1):
                    str_list = list(result[y-1])
                    str_list[x] = "#"
                    result[y-1] = "".join(str_list)
                # 左チェック
                if(x>=1):
                    str_list = list(result[y])
                    str_list[x-1] = "#"
                    result[y] = "".join(str_list)
                # 右チェック
                if(x<W-1):
                    str_list = list(result[y])
                    str_list[x+1] = "#"
                    result[y] = "".join(str_list)
                # 下チェック
                if(y<H-1):
                    str_list = list(result[y+1])
                    str_list[x] = "#"
                    result[y+1] = "".join(str_list)
            x += 1
        y += 1
    # 白があったら次へ
    for r in result:
        if("." in r):
            nexts = True
    cnts += 1
    li = copy.copy(result)

print(cnts)

Submission status: Wrong Answer

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

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

INF = 10**10
ans = -1
for y in range(H):
    for x in range(W):
        if A[y][x] == '.':
            l = INF
            for i in black:
                yy, xx = i
                l = min(l, abs(y-yy)+abs(x-xx))
            ans = max(ans, l)


print(ans)

Submission status: Wrong Answer

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


def bfs(queue: deque, reached: set) -> int:
    ans = 0
    dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    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:
                queue.appendleft((x, y, d[2] + 1))
                reached.add((x, y))
    return ans


queue = deque()
reached = set()
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            queue.append((i, j, 0))
            reached.add((i, j))
print(bfs(queue, reached))

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
A = [list(input()) for i in range(H)]
Ax = [[-1] * (W + 2) for i in range(H + 2)]

for hx in range(H + 1):
    for wx in range(W + 1):
        if hx != 0 and wx != 0:
            if A[hx - 1][wx - 1] == '#':
                Ax[hx][wx] = 0

excnt = 0

while 1:
    excnt += 1
    whcnt = 0
    for h in range(H + 1):
        for w in range(W + 1):
            if h != 0 and w != 0:
                if Ax[h][w] == -1:
                    whcnt += 1
                if Ax[h][w] != -1 and Ax[h][w] != excnt and (Ax[h - 1][w] == -1 or Ax[h + 1][w] == -1 or Ax[h][w - 1] == -1 or Ax[h][w + 1] == -1):
                    Ax[h - 1][w] = excnt
                    Ax[h + 1][w] = excnt
                    Ax[h][w - 1] = excnt
                    Ax[h][w + 1] = excnt
    if whcnt == 0:
        print(excnt)
        exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
b, c = map(int, input().split())
K = np.zeros((b,c))
for i in range(b):
    s = input()
    #print(s)
    for j in range(c):
        if s[j] == "#" :
            K[i,j] =1
print(K)
count = 0
while(1):
    count =count+1
    S = copy.deepcopy(K)
    for i in range(b):
        for j in range(c):
            if S[i,j] == 1:
                try:
                    K[i,j+1] =1
                    print("{},{}変更".format(i,j+1))
                except:
                    pass
                try:
                    if j != 0:
                        K[i,j-1] =1
                        print("{},{}変更".format(i,j-1))
                except:
                    pass
                try:
                    if i != 0:
                        K[i-1,j] =1
                        print("{},{}変更".format(i-1,j))
                except:
                    pass
                try:
                    K[i+1,j] =1
                    print("{},{}変更".format(i+1,j))
                except:
                    pass
    print(K)
    if np.all(K>0):
        break
    

print(count)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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


def is_white(h, w):
    return 0 <= h < H and 0 <= w < W and A[h][w] == '.'


hw = set()
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            if is_white(h + 1, w):
                hw.add((h + 1, w))
            if is_white(h - 1, w):
                hw.add((h - 1, w))
            if is_white(h, w + 1):
                hw.add((h, w + 1))
            if is_white(h, w - 1):
                hw.add((h, w - 1))

ans = 0
while len(hw) > 0:
    ans += 1
    nexts = set()
    while len(hw) > 0:
        h, w = hw.pop()
        A[h][w] = '#'
        if is_white(h + 1, w):
            nexts.add((h + 1, w))
        if is_white(h - 1, w):
            nexts.add((h - 1, w))
        if is_white(h, w + 1):
            nexts.add((h, w + 1))
        if is_white(h, w - 1):
            nexts.add((h, w - 1))
    hw = nexts
print(ans)

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[ ]:

"""
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[33]:

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 != 0):
        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(np.min(bin_masu))


# In[ ]: