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 sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(ns())

h, w = nm()
lis = [nsl() for _ in range(h)]
nextij = [(-1, 0), (0, -1), (1, 0), (0, 1)]
q1 = collections.deque()
q2 = collections.deque()

for i in range(len(lis)):
    for j in range(len(lis[i])):
        if lis[i][j] == '#':
            q1.append((i, j))
count = 0
while(len(q1) != 0 or len(q2) != 0):
    if count % 2 == 0:
        q2 = collections.deque()
        while(len(q1) != 0):
            x, y = q1.pop()
            for xx, yy in nextij:
                if 0 <= x + xx <= w - 1 and 0 <= y + yy <= h - 1:
                    if lis[y + yy][x + xx] == '.':
                        lis[y + yy][x + xx] = '#'
                        q2.append((y + yy, x + xx))
        if len(q2) == 0:
            print(count)
            exit()
    else:
        q1 = collections.deque()
        while(len(q2) != 0):
            x, y = q2.pop()
            for xx, yy in nextij:
                if 0 <= x + xx <= w - 1 and 0 <= y + yy <= h - 1:
                    if lis[y + yy][x + xx] == '.':
                        lis[y + yy][x + xx] = '#'
                        q1.append((y + yy, x + xx))
        if len(q1) == 0:
            print(count)
            exit()
    count += 1

Submission status: Wrong Answer

Solution code:
import copy
X = [int(i) for i in input().split()]
A = [[s=="#" for s in input()] for _ in range(X[0])]
for n in range(1,1000000):
    A_ = copy.deepcopy(A)
    for i in range(0,X[0]):
        for j in range(0,X[1]):
            up = max(0, i-1)
            down = min(i+1, X[0]-1)
            left = max(0, j-1)
            right = min(j+1, X[1]-1)
            # res = A[i][j]+A[up][j]+A[down][j]+A[i][right]+A[i][left]
            if A[i][j]:
                A_[i][j]=A_[up][j]=A_[down][j]=A_[i][right]=A_[i][left]=True
    A = copy.deepcopy(A_)
    if sum([sum(a) for a in A])==X[0]*X[1]:
        break
print(n)

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(pos):
    i, j = pos
    if i != 0 and (data[i - 1][j] == '#'):
        data[i][j] = '#'
    elif i != H - 1 and (data[i + 1][j] == '#'):
        data[i][j] = '#'
    elif j != 0 and (data[i][j - 1] == '#'):
        data[i][j] = '#'
    elif j != W - 1 and (data[i][j + 1] == '#'):
        data[i][j] = '#'


whiteList = []

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

    for pos in whiteList:
        enBlack(pos)

    whiteList = []

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = []
e = []
for h in range(H):
    for w in range(W):
        if hw[h][w] == '.':
            if w > 0 and h > 0:
                hw[h][w] = min([hw[h-1][w], hw[h][w-1]])+1
            elif w > 0:
                hw[h][w] = hw[h][w-1]+1
            elif h > 0:
                hw[h][w] = hw[h-1][w]+1
            else:
                hw[h][w] = 1
        else:
            hw[h][w] = 0

ans = 0
for _h in range(H):
    h = H-_h-1
    for _w in range(W):
        w = W-_w-1
        t = 2**32
        if hw[h][w] > 0:
            if w < (W-1) and h < (H-1):
                t = min([hw[h+1][w], hw[h][w+1]])+1
            elif w < (W-1):
                t = hw[h][w+1]+1
            elif h < (H-1):
                t = hw[h+1][w]+1
            else:
                t = 1
            hw[h][w] = min([t, hw[h][w]])
            if hw[h][w] > ans:
                ans = hw[h][w]
print(ans)

Submission status: Wrong Answer

Solution code:
ij = list(map(int, input().split()))
cor = []
num = 0
for y in range(ij[0]):
    index = [u for u, v in enumerate(str(input())) if v == '#']
    if index != []: 
        for x in index:
            cor.append([y, x])
    num = len(index) + num

if num == 1:
    max_x = max(ij[0] - (cor[0][0]+1), cor[0][0])
    max_y = max(ij[1] - (cor[0][1]+1), cor[0][1])
    print(max_x+max_y)

elif num > 1:
    min_cor = []
    for x in cor:
        max_x = max(ij[0] - (cor[0][0]+1), cor[0][0])
        max_y = max(ij[1] - (cor[0][1]+1), cor[0][1])
        cor_diff = []
        for y in cor:
            if x != y:
                diff_x = abs(x[1]-y[1])
                diff_y = abs(x[0]-y[0])
                cor_diff.append(diff_x+diff_y)
        min_cor.append(min(cor_diff))
    print(min(min_cor))

Submission status: Wrong Answer

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

A_list.insert(0,['z'*W])
A_list.append(['z'*W])

for hhh in range(H+2):
    A_list[hhh][0] = 'z' + A_list[hhh][0]
    A_list[hhh][0] = A_list[hhh][0] + 'z'

print(A_list)
    
    
black_points = []
for h in range(H+2):
    for w in range(W+2):
        if A_list[h][0][w] == '#':
            black_points.append([h,w])

counter = 0
while len(black_points)<H*W:
    counter += 1
    for hw in range(len(black_points)):
      if A_list[black_points[hw][0]-1][0][black_points[hw][1]] == '.':
            black_points.append([black_points[hw][0]-1, black_points[hw][1]])
          
      if A_list[black_points[hw][0]+1][0][black_points[hw][1]] == '.':
            black_points.append([black_points[hw][0]+1, black_points[hw][1]])
          
      if A_list[black_points[hw][0]][0][black_points[hw][1]-1] == '.':
            black_points.append([black_points[hw][0]-1, black_points[hw][1]-1])
          
      if A_list[black_points[hw][0]][0][black_points[hw][1]+1] == '.':
            black_points.append([black_points[hw][0], black_points[hw][1]+1])
print(counter)

Submission status: Wrong Answer

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

# 幅と高さの入力

[H_str, W_str] = input().split()
H = int(H_str)
W = int(W_str)

black_list = [] # 黒のマスリスト

# マス色の入力
A = []
for i in range(H):
    A_i = []
    A_i_str = input()
    for j in range(W):
        # 黒なら1, 白なら0として格納する
        # 黒ならblack_listに追加
        if A_i_str[j] == '#':
            black_list.append((i, j))


# 試行回数の計算
num = 0 # 試行回数
before = copy.deepcopy(black_list)
while (1):
    print(black_list)
    # 全部黒か確認
    black_square_number = len(black_list)
    if black_square_number >= H * W:
        break
    else:
        num += 1

    # ここから色替え操作
    added_black_list = []
    for (i, j) in before:
        if i != 0:
            if (i-1, j) not in added_black_list and (i-1, j) not in black_list:
                added_black_list.append((i-1, j))
        if i != H-1:
            if (i+1, j) not in added_black_list and (i+1, j) not in black_list:
                added_black_list.append((i+1, j))
        if j != 0:
            if (i, j-1) not in added_black_list and (i, j-1) not in black_list:
                added_black_list.append((i, j-1))
        if j != W-1:
            if (i, j+1) not in added_black_list and (i, j+1) not in black_list:
                added_black_list.append((i, j+1))

    before = copy.deepcopy(added_black_list)
    black_list.extend(added_black_list)

# 試行回数の出力
print("{}".format(num))

Submission status: Wrong Answer

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


def paint(a):
    for k in range(h):
        for l in range(w):
            if a[k][l]==".":
                return 1
            else:
                return 0
    for i in range(h-2):
        for j in range(w-2):
            if a[i+1][j+1]=="#":
                a[i][j+1]="#"
                a[i+2][j+1]="#"
                a[i+1][j]="#"
                a[i+1][j+2]="#"
    for p in range(h-2):
        if a[p+1][0]=="#":
            a[p][0]="#"
            a[p+1][1]="#"
            a[p+2][0]="#"
        if a[p+1][w-1]=="#":
            a[p][w-1]="#"
            a[p+1][w-2]="#"
            a[p+2][w-1]="#"
    for q in range(w-2):
        if a[0][q+1]=="#":
            a[0][q]="#"
            a[1][q+1]="#"
            a[0][q+2]="#"
        if a[h-1][q+1]=="#":
            a[h-1][q]="#"
            a[h-2][q+1]="#"
            a[h-1][q+2]="#"
            
    if a[0][0]=="#":
        a[0][1]="#"
        a[1][0]="#"
    elif a[h-1][0]=="#":
        a[h-1][1]="#"
        a[h-2][0]="#"
    elif a[0][w-1]=="#":
        a[0][w-2]="#"
        a[1][w-1]="#"
    elif [h-1][w-1]=="#":
        a[h-2][w-1]="#"
        a[h-1][w-2]="#"


ans=0
t=1
while t==1:
    t=paint(a)
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().rstrip().split(' ')))
a = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    inputs = [c for c in input().rstrip()]
    for j in range(W):
       a[i][j] = 0 if inputs[j] == '.' else 1 

x_list = [0 for _ in range(H + W - 1)]
for x in range(H + W - 1):
    for i in range(H):
        if x - i < 0 or x - i >= W:
            continue
        if a[i][x - i] == 1: 
            x_list[x] = 1
            break

sum_v = 0
current = 0
for v in x_list: 
    if v == 1:
        sum_v = max(sum_v, current)
        current = 0
    else:
        current += 1

print(sum_v)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = []
e = []
for h in range(H):
    for w in range(W):
        if hw[h][w] == '.':
            if w > 0 and h > 0:
                hw[h][w] = min([hw[h-1][w], hw[h][w-1]])+1
            elif w > 0:
                hw[h][w] = hw[h][w-1]+1
            elif h > 0:
                hw[h][w] = hw[h-1][w]+1
            else:
                hw[h][w] = 1
        else:
            hw[h][w] = 0

ans = 0
for _h in range(H):
    h = H-_h-1
    for _w in range(W):
        w = W-_w-1
        t = 2**32
        if w < (W-1) and h < (H-1):
            t = min([hw[h+1][w], hw[h][w+1]])+1
        elif w < (W-1):
            t = hw[h][w+1]+1
        elif h < (H-1):
            t = hw[h+1][w]+1
        else:
            t = 1
        hw[h][w] = min([t, hw[h][w]])
        if hw[h][w] > ans:
            ans = hw[h][w]
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
alist = [list(".{}.".format(input())) for j in range(H)]

s = ['.' for i in range(W + 2)]
alist.insert(0, s)
alist.append(s)

alist = [[(1 if i == '#' else 0) for i in j] for j in alist]

import copy
adumy = copy.deepcopy(alist)
is_proc = True
c = 0
while is_proc:
  is_proc = False
  
  for i in range(1, H+1):
    for j in range(1, W+1):
      n = alist[i][j] + max(alist[i][j-1], alist[i-1][j], alist[i+1][j], alist[i][j+1])
      adumy[i][j] = n
      
      if n == 0:
        is_proc = True

  alist = copy.deepcopy(adumy)
  #[print(j) for j in adumy]
  #print()
  
  c += 1

print(c)
  
  

#[print(j) for j in alist]

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.append(w-k + j + 1) for k in tmp]

brack1=sorted(list(set(brack1)))
brack2=sorted(list(set(brack2)))

brack1.append(h+w+1)
brack2.append(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 brack1[i]-b-1>ans:
            ans=brack1[i]-b-1
        b=brack1[i]
    if i<len(brack2):
        if brack2[i]-c-1>ans:
            ans=brack2[i]-c-1
        c=brack2[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
H,W = map(int,input().split())
A = []
B = []
for i in range(H):
    A.append([])
    B.append([])
for i in range(H):
    A[i] = list(input())
found = False
k = -1
B = copy.deepcopy(A)
while not found:
    found = True
    k += 1
    for i in range(H):
        for j in range(W):
            if A[i][j] == ".":
                found = False
                if i == 0:
                    if j == 0:
                        if A[i+1][j] =="#" or A[i][j+1] == "#":
                            B[i][j] = "#"
                    elif j == W-1:
                        if A[i+1][j] == "#" or A[i][j-1] == "#":
                            B[i][j] ="#"
                    else:
                        if A[i][j-1] == "#" or A[i][j+1] == "#" or A[i+1][j] == "#":
                            B[i][j] = "#"
                elif i == H-1:
                    if j == 0:
                        if A[i-1][j] =="#" or A[i][j+1] == "#":
                            B[i][j] = "#"
                    elif j == W-1:
                        if A[i-1][j] == "#" or A[i][j-1] == "#":
                            B[i][j] = "#"
                    else:
                        if A[i][j-1] == "#" or A[i][j+1] == "#" or A[i-1][j] == "#":
                            B[i][j] = "#"
                elif j == 0:
                    if A[i+1][j] == "#" or A[i][j+1] == "#" or A[i-1][j] == "#":
                            B[i][j] = "#"
                elif j == W-1:
                    if A[i+1][j] == "#" or A[i][j-1] == "#" or A[i-1][j] == "#":
                            B[i][j] = "#"
                else:
                    print(A[i+1][j],A[i][j-1],A[i][j+1],A[i-1][j])
                    if A[i+1][j] == "#" or A[i][j-1] == "#" or A[i-1][j] == "#" or A[i][j+1] == "#":
                            B[i][j] ="#"
    A = copy.deepcopy(B)
print(k)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
c_list = list()
for i in range(H):
  b = input()
  count_b = b.count('#')
  index = 0
  for x in range(count_b):
    index = b.find('#', index, -1)
    c_list.append([i, index])
      
ans = 0
if len(c_list) != H*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
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
alist = [list(".{}.".format(input())) for j in range(H)]

s = ['.' for i in range(W + 2)]
alist.insert(0, s)
alist.append(s)

alist = [[(1 if i == '#' else 0) for i in j] for j in alist]

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

    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] = '#'

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

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

    # 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
import numpy as np

A_list = []

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

for i in range(H):
    A_list.append(list(str(input())))

for h in range(H):
    for w in range(W):
        if A_list[h][w] == "#":
            A_list[h][w] = 1
        else:
            A_list[h][w] = 0

tmp_list1 = copy.deepcopy(A_list)  
tmp_list2 = copy.deepcopy(A_list)

"""
print(A_list)
print(tmp_list1)
"""

if np.sum(tmp_list2) == H*W:#操作不要の場合
    print("0")

Isitend = 0

count = 0
while(np.sum(tmp_list2) != H*W):
    #print(tmp_list2)
    count = count + 1
    tmp_list1 = copy.deepcopy(tmp_list2)
    for h in range(H):
        for w in range(W):
            if tmp_list1[h][w] == 1:
                if w>=1:
                    tmp_list2[h][w-1] = 1
                if w<=W-2:
                    tmp_list2[h][w+1] = 1
                if h>=1:
                    tmp_list2[h-1][w] = 1
                if h<=H-2:
                    tmp_list2[h+1][w] = 1
    

print(count)

Submission status: Wrong Answer

Solution code:
import copy

#入力取得
H, W = map(int, input().split())
l = [list(input()) for i in range(H)]


result = 0
flag = 1

index = list()

for i in range(len(l)):
    for j in range(len(l[0])):
        index.append([i,j])

while flag:
    flag = 0
    temp = copy.deepcopy(l)

    num = 0

    for k in index:
            if l[k[0]][k[1]] == "#":
                if k[0] + 1 < len(l):
                    if l[k[0] + 1][k[1]] == ".":
                        temp[k[0] + 1][k[1]] = "#"

                if k[1] + 1 < len(l[0]):
                    if l[k[0]][k[1] + 1] == ".":
                        temp[k[0]][k[1] + 1] = "#"

                if k[0] - 1 >= 0:
                    if l[k[0] - 1][k[1]] == ".":
                        temp[k[0] - 1][k[1]] = "#"

                if k[1] - 1 >= 0:
                    if l[k[0]][k[1] - 1] == ".":
                        temp[k[0]][k[1] - 1] = "#"

                if num != 0:
                    index.pop(num)

    for line in temp:
        if line.count('.') > 0:
            flag = 1
            break
    l = copy.deepcopy(temp)

    result = result + 1


print(result)

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 (0<=p[0]) and (p[0]<=w-1) and (0<=p[1]) and (p[1]<=h-1):
                         if field[p[1]][p[0]] == "#":
                              return cnt
                         if ans[p[1]][p[0]] != "#":
                              flag == min(flag,cnt + ans[p[1]][p[0]])
          cnt += 1
     return flag


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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

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, string_dict):
    regist_count = deepcopy(count)
    if 0 <= i < h and 0 <= j < w and string_dict[(i, j)][0] == '.':
        string_dict[(i, j)] = ('#', regist_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)
            string_dict = check_set_black(i-1, j, h, w, count, string_dict)
            string_dict = check_set_black(i, j + 1, h, w, count, string_dict)
            string_dict = check_set_black(i, j - 1, h, w, count, string_dict)

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

    if count > 100000000:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#A
import re

a,b = map(int,input().split())

c = [list(map(str,input().split()))for i in range(a)]
d = [[0 for j in range(b)]  for i in range(a)]

for i in range(a):#初期のリスト設定
    for j in range(b):
        if c[i][0][j] == '#':
            d[i][j] = 1

def change(save,d):
    for i in save:
        d[i[0]][i[1]] = 1

count = 0
for k in range(max(a,b)):
    count += 1
    save = []
    save2 = []
    for i in range(a):
        for j in range(b):
            if d[i][j] == 1:
                if i != 0:#上があるなら
                    if d[i-1][j] == 0:
                        save.append((i-1,j))
                if j != 0:
                    if d[i][j-1] == 0:#左があるなら
                        save.append((i,j-1))
                if i != a-1:
                    if d[i+1][j] == 0:#下があるなら
                        save.append((i+1,j))
                if j != b-1:
                    if d[i][j+1] == 0:#右があるなら
                        save.append((i,j+1))

    change(save,d)
    if len(save) == 0:
        break;
    print(d)
print(count-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:
        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)

l=len(black)

black2=black[:]
for i in range(N):
    black2=adblack(black2)
    black.extend(black2)
    black=delblack(black)
    
    if len(black)==N:
        print(i+1)
        break

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [["."]*w]*h
for i in range(h):
    a[i] = list(input())
s=0
e=0
k=0
while s==0:
    for i in range(h):
        for j in range(w):
            print(i,j)
            if a[i][j]=='#':
                for x in range(-1,2):
                    for y in range(-1,2):
                        if x+i >= 0 and x+i < h and y+j >= 0 and y+j < w and a[i+x][j+y] == '.':
                            a[i+x][j+y]='#'
            else:
                e=1
    if e==0:
        s=1
    k+=1
    e=0
print(k)

Submission status: Wrong Answer

Solution code:
print('Hello world!')

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

        flg = '.' in M[h]

    # 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:
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 k <=1:
        continue
    if min >= max:
      max = min
    
print(max)

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

        flg = '.' in M[h]

    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())
a=[input().split() for i in range(h)]

print(a)

def paint(a):
    for k in range(h):
        for l in range(w):
            if a[k][l]==".":
                return 1
            else:
                return 0
    for i in range(h-2):
        for j in range(w-2):
            if a[i+1][j+1]=="#":
                a[i][j+1]="#"
                a[i+2][j+1]="#"
                a[i+1][j]="#"
                a[i+1][j+2]="#"
    for p in range(h-2):
        if a[p+1][0]=="#":
            a[p][0]="#"
            a[p+1][1]="#"
            a[p+2][0]="#"
        if a[p+1][w-1]=="#":
            a[p][w-1]="#"
            a[p+1][w-2]="#"
            a[p+2][w-1]="#"
    for q in range(w-2):
        if a[0][q+1]=="#":
            a[0][q]="#"
            a[1][q+1]="#"
            a[0][q+2]="#"
        if a[h-1][q+1]=="#":
            a[h-1][q]="#"
            a[h-2][q+1]="#"
            a[h-1][q+2]="#"
            
    if a[0][0]=="#":
        a[0][1]="#"
        a[1][0]="#"
    elif a[h-1][0]=="#":
        a[h-1][1]="#"
        a[h-2][0]="#"
    elif a[0][w-1]=="#":
        a[0][w-2]="#"
        a[1][w-1]="#"
    elif [h-1][w-1]=="#":
        a[h-2][w-1]="#"
        a[h-1][w-2]="#"


ans=0
t=1
while t==1:
    t=paint(a)
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
#黒塗りの場所はいらない。白塗りのマス目だけ持っておいて
from collections import deque

def AllBlack(A,ncb):
    out = 0
    while ncb:
        i,j,k = ncb.popleft()
        if i+1 < H and A[i+1][j] != '#':
            A[i+1][j] = '#'
            ncb.append((i+1,j,k+1))
        if i-1 >= 0 and A[i-1][j] != '#':
            A[i-1][j] = '#'
            ncb.append((i-1,j,k+1))
        if j+1 < W and A[i][j+1] != '#':
            A[i][j+1] = '#'
            ncb.append((i,j+1,k+1))
        if j-1 >= 0 and A[i][j-1] != '#':
            A[i][j-1] = '#'
            ncb.append((i,j-1,k+1))
        out = k
    return out

H,W = map(int,input().split())
A = []
ncb = deque()
for i in range(H):
  A.append(list(input()))
  for j in range(W):
      if A == '#':
          ncb.append((i,j,0))

print(AllBlack(A,ncb))

Submission status: Wrong Answer

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

index = [["." for s in range( w + 2 ) ] for t in range ( h + 2 ) ]
index_init =[["." for u in range( w + 2 ) ] for v in range ( h + 2 ) ]

cnt_i = 0
cnt = 0


for a in range(h) :
    row =input()

    for b in range(w) :
        index[a+1][b+1] = row[b]

        if row[b] == ".":
            cnt_i += 1
            
while cnt_i > 0 :
    
    cnt += 1
    index_temp = index_init
    for j in range(h) :
        for i in range(w):
            if index[j+1][i+1] == "#" :
                index_temp[j+1] [i+1] = "#"
            else:
                if index[j][i+1] == "#" or index[j+1][i] == "#" or index[j+1][i+2] == "#" or index[j+2][i+1] == "#" :
                    index_temp[j+1][i+1] = "#"
                    cnt_i -= 1
  
    index = index_temp
    
print(cnt)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
e = [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:
#多分TLE
H, W = map(int, input().split())
A = []

A.append(['+']*(W+2))
for i in range(H):
    s=list(input())
    s.insert(0,'+')
    s.append('+')
    A.append(s)

A.append(['+']*(W+2))


"""
A.append(['#']*(W+2))
for i in range(H):
    s=list(input())
    s.insert(0,'#')
    s.append('#')
    A.append(s)

A.append(['#']*(W+2))
"""
def kuro(x,y):
    A[x-1][y]='+'
    A[x+1][y]='+'
    A[x][y-1]='+'
    A[x][y+1]='+'

flag=False
count=0
while flag == False:
    flag = True
    count+=1
    for i in range(1,H+1):
        for j in range(1,W+1):
            if A[i][j]=='#':
                if A[i-1][j]!='#':
                    A[i-1][j]='+'
                if A[i+1][j]!='#':
                    A[i+1][j]='+'
                if A[i][j-1]!='#':
                    A[i][j-1]='+'
                if A[i][j+1]!='#':
                    A[i][j+1]='+'


    for i in range(1,H+1):
        for j in range(1,W+1):
            if A[i][j]=='+':
                A[i][j]='#'
    
    for i in range(1,H+1):
        for j in range(1,W+1):
            if A[i][j] =='.':
                flag = False
print(count)