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:
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 allCellsAreBlack():
    for i in range(H):
        if '.' in data[i]:
            return False
    return True


def checkBlackCellnearby(h, w):
    if h != 0:
        if data[h - 1][w] == '#':
            return True
    if h != H-1:
        if data[h + 1][w] == '#':
            return True
    if w != 0:
        if data[h][w - 1] == '#':
            return True
    if w != W-1:
        if data[h][w + 1] == '#':
            return True
    else:
        return False


def enBlack(pos):
    i, j = pos
    data[i][j] = '#'


whiteList = []

while(True):
    for h in range(H):
        for w in range(W):
            if data[h][w] == '.' and checkBlackCellnearby(h, w):
                whiteList.append((h, w))

    for pos in whiteList:
        enBlack(pos)

    whiteList = []

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

Submission status: Wrong Answer

Solution code:
from queue import Queue

H,W=list(map(int,input().split()))
A=[]
for i in range(H):
    A.append(input())
    
INF = 10 ** 9
ans=0

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

dp = [[-1] * (H) for i in range(W)]

def bfs(sx,sy):
    D = [[0] * (H) for i in range(W)]
    q = Queue()
    q.put([sx, sy])
 
    while not q.empty():
        p = q.get()
        if dp[p[1]][p[0]]!=-1:
            return dp[p[1]][p[0]]+D[p[1]][p[0]]   
        if A[p[1]][p[0]]=="#":
            return D[p[1]][p[0]]
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if nx >= 0 and nx < W and ny >= 0 and ny < H:
                q.put([nx, ny])
                D[ny][nx] = D[p[1]][p[0]] + 1
                
for i in range(H):
    for j in range(W):
        if A[i][j]==".":
            dp[i][j]=bfs(i,j)
print(max(max(dp)))

Submission status: Wrong Answer

Solution code:
inf = float('inf')

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

e = [[inf for _ in range(W)] for _ in range(H)]


def next_pos(r, c):
    res = []
    for dr, dc in (-1, 0), (1, 0), (0, -1), (0, 1):
        nr = r + dr
        if not (0 <= nr < H): continue
        nc = c + dc
        if not (0 <= nc < W): continue
        if a[nr][nc] == '#': continue
        if e[nr][nc] < inf: continue
        res.append((nr, nc))
    return res


check_pos = []

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            check_pos += next_pos(r, c)

ans = 0
while True:
    # print(check_pos)
    ans += 1
    next_check_pos = []
    for r, c in check_pos:
        e[r][c] = ans
        next_check_pos += next_pos(r, c)
    else:
        if not next_check_pos: break
        check_pos = next_check_pos[::]

print(ans)

Submission status: Wrong Answer

Solution code:
first_input = list(map(int, input().split()))
height = first_input[0]
width = first_input[1]

area = []
for i in range(0, height):
  line = input()
  for k in range(0, width):
    area.append(line[k:k+1])

area_length = len(area)
answer = 0

target_indices = []
for i,item in enumerate(area):
  if item == '#':
    target_indices.append(i)

while(True):
  answer += 1
  appendedIndices = []
  for target_index in target_indices:
    # 左方向
    if target_index - 1 >= 0 and target_index % width != 0:
      area[target_index - 1] = '#'
      appendedIndices.append(target_index - 1)
    # 右方向
    if target_index + 1 < area_length and target_index % width != width-1:
      area[target_index + 1] = '#'
      appendedIndices.append(target_index + 1)
    # 下方向
    if target_index + width < area_length:
      area[target_index + width] = '#'
      appendedIndices.append(target_index + width)
    # 上方向
    if target_index - width >= 0:
      area[target_index - width] = '#'
      appendedIndices.append(target_index - width)
  target_indices.extend(appendedIndices)
  appendedIndices = []
  if '.' not in area:
    break

print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

i = list(map(int, input().split()))
#print("H : " + str(i[0]))
#print("W : " + str(i[1]))

list = []
for s in range(i[0]):
    list.append((input()))
    
#print(list)

result = 0
for y in list:
    if y == '...':
        result +=1
        
print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
import math

# [競プロ等におけるpython3の標準入力 \- Qiita](https://qiita.com/zenrshon/items/c4f3849552348b3dbe67)
# [Pythonのリスト（配列）の特定の要素を抽出、置換、変換 \| note\.nkmk\.me](https://note.nkmk.me/python-list-select-replace/)

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = np.array([[1 if s == '#' else 0 for s in l.strip()] for l in stdin])

# [NumPy配列ndarrayの対角成分の抽出、対角行列の作成（diag, diagonal） \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-diag-diagonal/)

max = 0
tmp = 0
cnt = 0

# 右上から斜め方向に走査する
for i in range(W+H-1):
    # [NumPy配列ndarrayから条件を満たす要素・行・列を抽出、削除 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-condition/)
    if np.any(A.diagonal(W - 1 - i) == 1):
        if cnt == 0  :
            cnt = 1 
            if max < tmp:
                max = tmp
                tmp = 0

        if cnt == 1 and max < math.ceil(tmp / 2) :
            max = math.ceil(tmp / 2)
            tmp = 0
    else : 
        tmp = tmp + 1

if max < tmp :
    max = tmp

print(max)

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 allCellsAreBlack(arr):
    for i in range(H):
        if '.' in data[i]:
            return False
    return True


def checkBlackCellnearby(h, w):
    if h != 0:
        if data[h - 1][w] == '#':
            return True
    if h != H-1:
        if data[h + 1][w] == '#':
            return True
    if w != 0:
        if data[h][w - 1] == '#':
            return True
    if w != W-1:
        if data[h][w + 1] == '#':
            return True
    else:
        return False


def enBlack(pos):
    i, j = pos
    data[i][j] = '#'


whiteList = []

while(True):
    for h in range(H):
        for w in range(W):
            if data[h][w] == '.' and checkBlackCellnearby(h, w):
                whiteList.append((h, w))

    for pos in whiteList:
        enBlack(pos)

    whiteList = []

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

Submission status: Wrong Answer

Solution code:
h,w = [int(i) for i in input().split()]
x = []
for i in range(h):
    x.append(input())

search = []
board = {}
for i in range(h):
    for j in range(w):
        if x[i][j] == "#":
            board[(i,j)] = 0
            search.append((i,j))

count = 1
ans = 0
while search:
    search2 = []
    for xy in search:
        x,y = xy
        if (x+1,y) not in board and x+1 <w:
            board[(x+1,y)] = count
            search2.append((x+1,y))
            ans = count
        if (x-1,y) not in board and x-1 >=0:
            board[(x-1,y)] = count
            search2.append(((x-1,y)))
            ans = count
        if (x,y+1) not in board and y+1 <h:
            board[(x,y+1)] = count
            search2.append((x,y+1))
            ans = count
        if (x,y-1) not in board and y-1 >=0:
            board[(x,y-1)] = count
            search2.append((x,y-1))
            ans = count
    search = search2
    count +=1

print(ans)

Submission status: Wrong Answer

Solution code:
first_input = list(map(int, input().split()))
height = first_input[0]
width = first_input[1]

area = []
for i in range(0, height):
  line = input()
  for k in range(0, width):
    area.append(line[k:k+1])

area_length = len(area)
answer = 0

target_indices = []
for i,item in enumerate(area):
  if item == '#':
    target_indices.append(i)

while(True):
  answer += 1
  appendedIndices = []
  for target_index in target_indices:
    # 左方向
    if target_index - 1 >= 0 and target_index % width != 0:
      area[target_index - 1] = '#'
      appendedIndices.append(target_index - 1)
    # 右方向
    if target_index + 1 < area_length and target_index % width != width-1:
      area[target_index + 1] = '#'
      appendedIndices.append(target_index + 1)
    # 下方向
    if target_index + width < area_length:
      area[target_index + width] = '#'
      appendedIndices.append(target_index + width)
    # 上方向
    if target_index - width >= 0:
      area[target_index - width] = '#'
      appendedIndices.append(target_index - width)
  target_indices.extend(appendedIndices)
  if '.' not in area:
    break

print(answer)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
brack1=[]
brack2=[]
for j in range(h):
    tmp=[i for i, x in enumerate(a[j]) if x == '#']
    [brack1.append(k+1+j+1) for k in tmp]
    [brack2.insert(0,m+1+j+1) for m in tmp]

#brack1=list(set(brack1))
#brack2=list(set(brack2))

brack1.append(h+w+1)
brack2.insert(0,h+w+1)

if len(brack1)>=len(brack2):
    B=len(brack1)
else:
    B=len(brack2)



b=1
c=1
ans=0
for i in range(B):
    if i < len(brack1):
        if abs(brack1[i]-b)-1>ans:
            ans=abs(brack1[i])-b-1
        b=brack1[i]
    if i<len(brack2):
        if abs(brack2[-(i+1)]-c)-1>ans:
            ans=abs(brack2[-(i+1)]-c)-1
        c=brack2[-(i+1)]
        
print(ans)

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
man=str(map)
maa=man.find("0")
if maa==-1:
    print(0)
else:
    ans=[]
    for h in range(H):
        for w in range(W):
            if map[h][w]==0:
                i=1
                while i<H+W:
                    if h-i>=0:
                        if map[h-i][w]==1:
                            ans.append(i)
                            break
                    else:
                        ans.append(i)
                        break
                    if w-i>=0:
                        if map[h][w-i]==1:
                            ans.append(i)
                            break
                    else:
                        ans.append(i)
                        break
                    if h+i<H:
                        if map[h+i][w]==1:
                            ans.append(i)
                            break
                    else:
                        ans.append(i)
                        break
                    if w+i<W:
                        if map[h][w+i]==1:
                            ans.append(i)
                            break
                    else:
                        ans.append(i)
                        break


                    i=i+1
    print(max(ans))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
#H,W = 1000,1000
A = [ [0 for ii in range(W)] for i in range(H)]
for i in range(H):
  Ain = input()
  Ain = Ain.replace(".","0")
  Ain = Ain.replace("#","1")
  A[i] = list(map(int, list(Ain)))
#A[100][100] = 1
dp = [[10000 for i in range(W)] for ii in range(H)]
points = []
for yi in range(H):
  for xi in range(W):
    if A[yi][xi] == 1:
      points.append([yi,xi,0])

for y,x,now in points:
  if now >= dp[y][x]:
    continue
  dp[y][x] = now
  newd = now + 1
  if (y > 0) and (A[y-1][x] == 0):
    points.append([y-1,x,newd])
  if (y < H-1) and (A[y+1][x] == 0):
    points.append([y+1,x,newd])
  if (x > 0) and (A[y][x-1] == 0):
    points.append([y,x-1,newd])
  if (x < W-1) and (A[y][x+1] == 0):
    points.append([y,x+1,newd])

print( max(max(dp)) )

Submission status: Wrong Answer

Solution code:
h,w=[int(i) for i in input().split()]
a=[input() for _ in range(h)]
b=[["."]*h for _ in range(w)]
for i in range(w):
    for j in range(h):
        if a[j][i]=="#":
            b[i][j]="#"
cnt_yoko=[0]*h
cnt_tate=[0]*w
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            cnt_yoko[i]+=1
for i in range(w):
    for j in range(h):
        if a[j][i]=="#":
            cnt_tate[i]+=1
ans=0
for i in range(min(h,w)):
    ans=max(ans,cnt_tate[i]+cnt_yoko[i])
if h>w:
    for i in range(h):
        ans=max(ans,cnt_yoko[i])
else:
    for i in range(w):
        ans=max(ans,cnt_tate[i])
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
A = 0
delR = 0
delL = 0
for h in range(H):
    for w, x in zip(range(W), input()):
        if x == "#":
            A |= 1 << H * h + w
        if w == 0:
            delR |= 1 << H * h + w
        elif w == W-1:
            delL |= 1 << H * h + w

import numpy as np

MASK = pow(2, W * H) - 1
MASKSUM = MASK * H
i = 0
while True:
    if A == MASK:
        break
    WK = A
    A |= ((WK << W) & MASK) | (WK >> W) | (((WK^(WK & delL)) << 1)&MASK) | ((WK^(WK & delR)) >> 1)
    i += 1

print(i)

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:
h,w=map(int,input().split())
a=[]
for i in range(h):
    tmp=input()
    tmp2=[]
    for j in tmp:
        if j=='.':
            a.append(0)
        else:
            a.append(1)
b=[i for i, x in enumerate(a) if x == 1]
c=[]
count=0
while len(b)<h*w/2:
    count=count+1
    for i in b:
        if i%h!=h-1:
            c.append(i+1)
        if i%h!=0:
            c.append(i-1)
        if i>=h:
            c.append(i-h)
        if i+h<h*w:
            c.append(i+h)
    b.extend(c)
    d=list(set(b))
    b=d
    c=[]
print(count)

Submission status: Wrong Answer

Solution code:
import copy
H, W = map(int,input().split())
print(H, W)
A = [[0 for j in range(W)] for i in range (H)]
B = [[0 for j in range(W)] for i in range (H)]
for i in range(H):
  j = 0
  Abak = list(input())
  for x in Abak:
    if x == '#':
      A[i][j] = 1
    j = j + 1

cnt = 0
while True:
  B = [x[:] for x in A]
  cnt2 = 0
  for i in range(H):
    if 0 in A[i]:
      cnt2 = 1
      if i > 0:
        B[i] = [x + y for (x, y) in zip(A[i-1], B[i])]
      if i < H - 1:
        B[i] = [x + y for (x, y) in zip(A[i+1], B[i])]
      for j in range(W):
        #print('i',i,'j',j)
        if B[i][j]==0:
          if j > 0:
            if A[i][j-1] == 1:
              B[i][j] = 1
          if j < W-1:
            if A[i][j+1] == 1:
              B[i][j] = 1
  if cnt2 == 0:
    break
  A = list(map(lambda x,y: list(map(lambda a,b: a+b, x,y)), A, B))
  # A = [x + y for (x, y) in zip(A, B)]
  # print(A)
  cnt = cnt + 1;
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys
import copy

def solve(h, w, a):
    direct = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    count = 0
    a_tmp = copy.deepcopy(a)
    while True:
        for i in xrange(h):
            for j in xrange(w):
                if a[i][j] == "#":
                    a_tmp[i][j] = "#"
                    for x, y in direct:
                        if 0 <= i + x < h and 0 <= j + y < w:
                            a_tmp[i+x][j+y] = "#"

        count += 1
        a = copy.deepcopy(a_tmp)
        flag = True
        for i in xrange(h):
            for j in xrange(w):
                if a[i][j] == ".":
                    flag = False
                a_tmp[i][j] = "."
        if flag == True:
            return count

if __name__ == '__main__':

    h, w = map(int, sys.stdin.readline().strip().split(" "))
    a = []
    for i in xrange(h):
       a.append([])
       line = sys.stdin.readline().strip()
       for j in xrange(w):
           a[i].append(line[j])
    ans = solve(h, w, a)
    print ans

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
field=[input() for x in range(H)]
f_f = [[0 for x in range(W)]for y in range(H)]

lis = []
my = 0
for y in field:
    mx = 0
    for x in y:
        if x == '#':
            lis.append([my,mx])
            f_f[my][mx] = 1
        mx+=1
    my+=1
vy=[0,0,1,-1]
vx=[1,-1,0,0]

i=0
if len(lis) == 1:
    i = 1
flag = -1
def change(lis):
    global i,flag
    while lis:
        if abs(flag-len(lis))>2:
            i+=1
        flag = len(lis)
        y,x = lis.pop(0)
        for dy,dx in zip(vy,vx):
            ny,nx = y+dy,x+dx
            if 0<=ny<H and 0<=nx<W:
                if f_f[ny][nx] == 0:#.
                    f_f[ny][nx] = 1
                    lis.append([ny,nx])
                
    return i
print(change(lis))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H,W = map(int,input().split())
A = [list('a'*(W+2))]+[['a']+list(input())+['a'] for _ in range(H)]+[list('a'*(W+2))]
ans = 0
flag = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j] == '.':
            flag = 0
            a = 1
            while 1:
                for c in range(a+1):
                    if flag == 1:break
                    for d in range(a+1):
                        if any([A[min(i+a,H)][j]=='#',A[max(i-a,0)][j]=='#',A[i][min(j+a,W)]=='#',A[i][max(j-a,0)]=='#']):
                            ans = max(ans,a)
                            #print(ans,a)
                            flag = 1
                            break
                        if any([A[min(i+c,H)][min(j+d,W)]=='#',A[min(i+c,H)][max(j-d,0)]=='#',A[max(i-c,0)][min(j+d,W)]=='#',A[max(i-c,0)][max(j-d,0)]=='#']):
                            #print(ans,c,d)
                            ans = max(ans,c+d)
                            flag = 1
                            break
                if flag == 1:break
                a+=1
print(ans)

Submission status: Wrong Answer

Solution code:
first_input = list(map(int, input().split()))
height = first_input[0]
width = first_input[1]

area = []
for i in range(0, height):
  line = input()
  for k in range(0, width):
    area.append(line[k:k+1])

area_length = len(area)
answer = 0

while(True):
  answer += 1
  target_indices = []
  for i,item in enumerate(area):
    if item == '#':
      target_indices.append(i)
  for target_index in target_indices:
    # 左方向
    if target_index - 1 >= 0 and target_index % width != 0:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length and target_index % width != width-1:
    	area[target_index + 1] = '#'
    # 下方向
    if target_index + width < area_length:
    	area[target_index + width] = '#'
    # 上方向
    if target_index - width >= 0:
    	area[target_index - width] = '#'
  target_indices = []
  if '.' not in area:
    break
print(answer)

Submission status: Wrong Answer

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


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

counter = 0
while True:
    counter += 1
    new = []
    for black in black_list:
        for (i, j) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nh = black[0] + i
            nw = black[1] + j
            if 0 <= nh and nh < h and 0 <= nw and nw < w and s[nh][nw] == '.':
                new.append([nh, nw])
                s[nh][nw] = '#'

    black_list.extend(new)
    if len(black_list) == h * w:
        break
print(counter)

Submission status: Wrong Answer

Solution code:
import copy
h, w = map(int, input().split())
a = [["."]*w]*h
for i in range(h):
    a[i] = list(input())
k=0
while True:
    b = copy.deepcopy(a)
    for i in range(h):
        for j in range(w):
            if b[i][j]=='#':
                for x in [-1,1]:
                    if x+i >= 0 and x+i < h:
                            if a[i+x][j] == '.':
                                a[i+x][j]='#'
                for y in [-1,1]:
                        if y+j >= 0 and y+j < w:
                            if a[i][j+y] == '.':
                                a[i][j+y]='#'

    k+=1
    e=0
    for i in range(h):
        for j in range(w):
            if a[i][j]=='.' or e==1:
                e=1
                break
        if e==1:
            break
    if e == 0:
        break
print(k)

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)

white = []

for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            white.append([i, j])

number1 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number1[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number1[i - 1][j]) + 1)
        else:
            number.append(0)
    number1.append(number)

#print(number1)

number2 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[i][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number2[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number2[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    number.reverse()
    number2.append(number)

#print(number2)

number3 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][j] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number3[i - 1][j] + 1)
                else:
                    number.append(min(number[j - 1], number3[i - 1][j]) + 1)
        else:
            number.append(0)
    number3.append(number)

number3.reverse()

number4 = []
for i in range(h):
    number = []
    for j in range(w):
        if a[- i - 1][- j - 1] == ".":
            if i == 0:
                if j == 0:
                    number.append(2000)
                else:
                    number.append(number[j - 1] + 1)
            else:
                if j == 0:
                    number.append(number4[i - 1][- j - 1] + 1)
                else:
                    number.append(min(number[j - 1], number4[i - 1][- j - 1]) + 1)
        else:
            number.append(0)
    number.reverse()
    number4.append(number)

number4.reverse()

#print(number4)

number5 = []

print(0)
"""
else:
    for i in range(len(white)):
        number5.append(min(number1[white[i][0]][white[i][1]], number2[white[i][0]][white[i][1]], number3[white[i][0]][white[i][1]], number4[white[i][0]][white[i][1]]))
    print(max(number5))
"""

Submission status: Wrong Answer

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

non=3000
import numpy as np
b=np.ones((h,w),dtype=int)*non

ans=0

u=np.ones((h,w),dtype=int)*non
for i in range(h):
    l=np.ones(w,dtype=int)*non
    for j in range(w):
        if a[i][j]=='#':
            l[j:]=np.arange(w-j,dtype=int)
    r=non
    for j in range(w-1,-1,-1):
        if a[i][j]=='#':
            b[i][j]=0
            r=0
        elif j<w-1 and r!=non:
            r+=1
        b[i][j]=min(l[j],r)
    if i>0:
        u[i]=np.min((b[i],b[i-1]+1),axis=0)
d=np.ones(w,dtype=int)*non
for i in range(h-1,-1,-1):
    if i<h-1:
        d=np.min((b[i],b[i+1]+1),axis=0)
    b[i]=np.min((u[i],d),axis=0)
    ans=max(ans,np.max(b[i]))
print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    h,w = map(int,input().split())
    Map = []
    x, y = [],[]
    count = 0
    # for _ in range(h):
    #     Map.append(input())
    Map = [list(input()) for _ in range(h)]

    x,y = 0,0

    # x,y = return_kuro(Map,h)
    while judge(Map):
        x, y = return_kuro(Map,h)
        for Len in range(len(x)):
            for row in range(h):
                for col in range(w):
                    if row == x[Len] or col == y[Len]:
                        Map[row][col] = "#"
                        print(Map)
        count += 1
        # print(Map)
    print(count)
        
def judge(Map):
    j = False
    for l in Map:
        if l.count(".") > 0:
            j = True
            break
    return j

def return_kuro(Map, h):
    x,y = [],[]
    for row in range(h):
        if Map[row].count("#") > 0 and Map[row].count(".") > 0:
            x.append(i for i, x in enumerate(Map[row]) if x == "#")
            y.append(int(row))
    print(x, y)
    return x,y

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

# [競プロ等におけるpython3の標準入力 \- Qiita](https://qiita.com/zenrshon/items/c4f3849552348b3dbe67)
# [Pythonのリスト（配列）の特定の要素を抽出、置換、変換 \| note\.nkmk\.me](https://note.nkmk.me/python-list-select-replace/)

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = np.array([[1 if s == '#' else 0 for s in l.strip()] for l in stdin])

# [NumPy配列ndarrayの対角成分の抽出、対角行列の作成（diag, diagonal） \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-diag-diagonal/)

max = 0
tmp = 0

# 右上から斜め方向に走査する
for i in range(W+H-1):
    # [NumPy配列ndarrayから条件を満たす要素・行・列を抽出、削除 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-condition/)
    if np.any(A.diagonal(W - 1 - i) == 1) and (len(A.diagonal(W - 1 - i)) > 1) :
        if max < tmp :
            max = tmp
            tmp = 0
    else : 
        tmp = tmp + 1

if max < tmp :
    max = tmp

print(max)

Submission status: Wrong Answer

Solution code:
import copy
h, w = map(int, input().split())
a = [["."]*w]*h
for i in range(h):
    a[i] = list(input())
k=0
while True:
    b = copy.deepcopy(a)
    for i in range(h):
        for j in range(w):
            if b[i][j]=='#':
                for x in [-1,1]:
                    if x+i >= 0 and x+i < h:
                            if a[i+x][j] == '.':
                                a[i+x][j]='#'
                for y in [-1,1]:
                        if y+j >= 0 and y+j < w:
                            if a[i][j+y] == '.':
                                a[i][j+y]='#'

    k+=1
    e=0
    for i in range(h):
        for j in range(w):
            if a[i][j]=='.':
                e=1
                break
        if e==1:
            break
    if e == 0:
        break
print(k)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

H,W = read_int()
A = [list(" ".join(read_str().split())) for _ in range(H)]

def solve():
    ans = 1
    end = True
    while True:
        for i in range(H):
            for j in range(W):
                if A[i][j] == ".":
                    end = False
                if A[i][j] == "#":
                    if 1 <= i:
                        A[i - 1][j] = "#"
                    if i < H-1:
                        A[i + 1][j] = "#"
                    if -1 <= j:
                        A[i][j - 1] = "#"
                    if j < W-1:
                        A[i][j + 1] = "#"
        if end: break
        ans += 1
        end = True
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

# [競プロ等におけるpython3の標準入力 \- Qiita](https://qiita.com/zenrshon/items/c4f3849552348b3dbe67)
# [Pythonのリスト（配列）の特定の要素を抽出、置換、変換 \| note\.nkmk\.me](https://note.nkmk.me/python-list-select-replace/)

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = np.array([[1 if s == '#' else 0 for s in l.strip()] for l in stdin])

# [NumPy配列ndarrayの対角成分の抽出、対角行列の作成（diag, diagonal） \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-diag-diagonal/)

max = 0
tmp = 0

# 右上から斜め方向に走査する
for i in range(W+H-1):
    # [NumPy配列ndarrayから条件を満たす要素・行・列を抽出、削除 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-condition/)
    if np.any(A.diagonal(W - 1 - i) == 1) and (len(A.diagonal(W - 1 - i)) > 1) :
        if max < tmp :
            max = tmp
            tmp = 0
    else : 
        tmp = tmp + 1
        #print(tmp)
    print(i)

if max < tmp :
    max = tmp

print(max)

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] = 1
      else:
        pass
  for f in range(H*W*2+3*W):
    if t[f] == 1:
      t[f] = "#"
  r += 1
  if t.count(".") == 0:
    break
print(r)