Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

3



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


Sample output:
2

Submission status: Wrong Answer

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

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

string_dict = {}


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


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


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

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

    if count > 100:
        break
    count += 1


print(count)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits



def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))

def update(bit,i, dp):
    bit[i] = dp
    return bit

def query(bit, i):
    lis = [bit[j] for j in range(i)]
    return max(lis)


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()

a = [input() for _ in range(H)]

black = [[i,j] for i in range(H) for j in range(W) if a[i][j]=='#']
lis_hidariue = [x[0]+x[1] for x in black]
lis_migiue = [ W + x[0] - x[1] - 1 for x in black]
lis_hidarishita = [H - x[0] + x[1]-1 for x in black]
lis_migishita = [H + W - x[0] - x[1]-2 for x in black]

ct_black = len(black)

#print(black)

dis_kabe = max(min(lis_hidarishita),min(lis_hidariue),min(lis_migishita),min(lis_migiue))
#print(dis_kabe)

dis_point = []

if ct_black>=2:
    for i in range(ct_black-1):
        tmp = []
        for j in range(i+1, ct_black):
            tmp.append(abs(black[j][0] - black[i][0]) + abs(black[j][1] - black[i][1]))
        dis_point.append(int(min(tmp)/2)+1)
        #print('i:',i,'j:',j ,'dis_point:',dis_point)

    print(max(dis_kabe, max(dis_point)))
else:
    print(dis_kabe)

Submission status: Wrong Answer

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

M = {};

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


#print(M)

count = 0

#flg = False

import copy

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

while True:
    #flg = False

    #temp = [x[:] for x in M]

    temp = copy.deepcopy(M)

    count += 1

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

            else:
                f[h][w] = 1

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

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

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

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

    flg = True

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

        if flg == True:
            break

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

    if flg != True:
        break


print(count)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
b=[1]*h
k=max(h,w)-1
K=0
L=0
l=0
s=0
c=0
for i in range(h):
  K=0
  k=max(h,w)-1
  b[i]=[1]*w
  for j in range(w):
    b[i][j]=k-l
    a[i][j]=="#"
    s+=(k-l)
    c+=1
    if k==max(h,w)//2 or K==1:
      k+=1
      K=1
    else:
      k-=1
  if l==max(h,w)//2 or L==1:
    l-=1
    L=1
  else:
    l+=1
print(s//c)

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

Submission status: Wrong Answer

Solution code:
from heapq import*
import sys;sys.setrecursionlimit(200000)
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#") for x in range(h)]+[["#"]*(w+2)]

g=0
x=1
y=1
lock=[]
for y in range(1,1+h):
    for x in range(1,1+w):
        if grid[y][x]=="#":
            heappush(lock,(y,x))
#print(lock)


while 1:
    locked=[]
    for y,x in lock:
        if grid[y][x]=='#':
            for i,j in([0,1],[1,0],[0,-1],[-1,0]):
                if grid[y+i][x+j]!="#":
                    if (y+i,x+j)in locked:
                        continue
                    else:
                        grid[y+i][x+j]="#"
                        heappush(locked,(y+i,x+j))
    g+=1
    lock=locked
#    print(lock)
#    for i in grid:
#        print(*i)
#    print()
    if all(all(j=="#" for j in i)for i in grid):
        print(g)
        exit()

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()) for _ in range(H)]

counter = 0


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

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

tmpList = []

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

    for pos in tmpList:
        enBlack(data, pos)

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

Submission status: Wrong Answer

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


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

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

Submission status: Wrong Answer

Solution code:
H,W = [int(x) for x in input().split(' ')]

A = []
A.append([-1]*(W+2))
zclist = []
for i in range(H):
  b = [-1]
  a1 = input()
  for j in range(W):
    if a1[j] == '.':
      b.append(0)
      zclist.append((i+1,j+1))
      
    else:
      b.append(1)

  b.append(-1)
  A.append(b)
A.append([-1]*(W+2))

zcnt = 0
while True:
  V = []
  nz = []
  for zz in zclist:
    j,i = zz
    v0 = (A[j-1][i] == 1)
    v1 = (A[j][i-1] == 1)
    v2 = (A[j][i+1] == 1)
    v3 = (A[j+1][i] == 1)
    vc = v0 or v1 or v2 or v3
    if vc == True:
      V.append(zz)
    else:
      nz.append(zz)
  for v in V:
    j,i = v
    A[j][i] = 1
  #print(V)
  zclist = nz
  zcnt+=1
  
  if len(nz) == 0:
    break


  
print(zcnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#import copy
import random

H, W = map(int, input().split())
#dist_matrix = [[10000] * W for i in range(H)]
black_h_list = []
black_w_list = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      black_h_list.append(i)
      black_w_list.append(j)

#print(black_h_list)
#print(black_w_list)

max_value = 0
for index in range(100):
  i = int(random.random()*H)
  j = int(random.random()*W)
  min_dist = H+W+2
  for k in range(len(black_h_list)):
    dist = abs(i-black_h_list[k]) + abs(j-black_w_list[k])
    if max_value >= dist:
      min_dist = dist
      break
    elif min_dist > dist:
      min_dist = dist        
  #dist_matrix[i][j] = min_dist
  if max_value < min_dist:
    max_value = min_dist

#print(dist_matrix)
    
print(max_value)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
H, W = 0, 0
A = []


def set_inputs():
    global H, W, A
    H, W = get_li()
    A = get_data(H, [str])
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    remaining = set()
    completed = set()
    for i, ai_ in enumerate(A):
        for j, a in enumerate(ai_):
            if a == ".":
                continue
            if i > 0 and A[i-1][j] == "#" and i < H - 1 and A[i+1][j] == "#" and j > 0 and A[i][j-1] == "#" and j < W - 1 and A[i][j+1] == "#":
                completed.add((i, j))
                continue
            remaining.add((i, j))
    ans = 0
    while remaining:
        _next = set()
        for (i, j) in remaining:
            completed.add((i, j))
            if i > 0 and (i-1, j) not in completed:
                _next.add((i-1, j))
            if i < H - 1 and (i+1, j) not in completed:
                _next.add((i+1, j))
            if j > 0 and (i, j-1) not in completed:
                _next.add((i, j-1))
            if j < W - 1 and (i, j+1) not in completed:
                _next.add((i, j+1))
        remaining = _next
        ans += 1
    print(ans - 1)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

h, w = list(map(int, input().split()))
black_list = []
for i in range(h):
  for j, val in enumerate(list(input())):
    if val == "#":
      black_list.append([i,j])
max_val = 0
for i in range(h):
  for j in range(w):
    for point in black_list:
      diff = abs(i-point[0]) + abs(j-point[1])
      if diff > max_val:
        max_val = diff
print(max_val)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
H, W = map(int, input().split())
bp = []
for i in range(H):
    s = input()
    for j, e in enumerate(s):
        if e == '#':
            bp.append((i, j))
if len(bp) == 1:
    d1 = abs(bp[0][0]-0) + abs(bp[0][1]-0)
    d2 = abs(bp[0][0]-0) + abs(bp[0][1]-(W-1))
    d3 = abs(bp[0][0]-(H-1)) + abs(bp[0][1]-0)
    d4 = abs(bp[0][0]-(H-1)) + abs(bp[0][1]-(W-1))
    print(max([d1, d2, d3, d4]))
else:
    d = {}
    for v in combinations(bp, 2):
        if v[0] in d.keys():
            d[v[0]] = min(d[v[0]], abs(v[0][0]-v[1][0])+abs(v[0][1]-v[1][1]))
        else:
            d[v[0]] = abs(v[0][0]-v[1][0])+abs(v[0][1]-v[1][1])
    print(max(d.values())-1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#import copy
import random

H, W = map(int, input().split())
#dist_matrix = [[10000] * W for i in range(H)]
black_h_list = []
black_w_list = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      black_h_list.append(i)
      black_w_list.append(j)

#print(black_h_list)
#print(black_w_list)

max_value = 0
for index in range(1000):
  i = int(random.random()*H)
  j = int(random.random()*W)
  min_dist = H+W+2
  for k in range(len(black_h_list)):
    dist = abs(i-black_h_list[k]) + abs(j-black_w_list[k])
    if max_value >= dist:
      min_dist = dist
      break
    elif min_dist > dist:
      min_dist = dist        
  #dist_matrix[i][j] = min_dist
  if max_value < min_dist:
    max_value = min_dist

#print(dist_matrix)
    
print(max_value)

Submission status: Wrong Answer

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

M = {};

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


#print(M)

count = 0

#flg = False

import copy

while True:
    #flg = False

    #temp = [x[:] for x in M]

    temp = copy.deepcopy(M)

    count += 1

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

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

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

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

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

    flg = True

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

        if flg == True:
            break

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

    if flg != True:
        break


print(count)

Submission status: Wrong Answer

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

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

string_dict = {}


for i in range(int(h)):
    for j in range(int(w)):
        string_dict[(i, j)] = ('.', 0)

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


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


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

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

    if count > 10000:
        break
    count += 1


print(count)

Submission status: Wrong Answer

Solution code:
#import copy
import random

H, W = map(int, input().split())
#dist_matrix = [[10000] * W for i in range(H)]
black_h_list = []
black_w_list = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      black_h_list.append(i)
      black_w_list.append(j)

#print(black_h_list)
#print(black_w_list)

max_value = 0
for index in range(1000):
  i = int(random.random()*(H+1))
  j = int(random.random()*(W+1))
  min_dist = H+W+2
  for k in range(len(black_h_list)):
    dist = abs(i-black_h_list[k]) + abs(j-black_w_list[k])
    if max_value >= dist:
      min_dist = dist
      break
    elif min_dist > dist:
      min_dist = dist        
  #dist_matrix[i][j] = min_dist
  if max_value < min_dist:
    max_value = min_dist

#print(dist_matrix)
    
print(max_value)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy

h_max,w_max = [int(i) for i in input().split()]
a = [input() for i in range(h_max)]

numOfBlack = 0
result = 0

while(numOfBlack < (h_max * w_max)):
    a_tmp = copy.deepcopy(a)
    numOfBlack = 0
    for h in range(h_max):
        if(a[h].count('#') == 0):
            continue
        for w in range(w_max):
            if(a[h][w] == '#'):
                if((h-1) >= 0):
                    a_tmp[h-1] = a_tmp[h-1][:w] +'#' + a_tmp[h-1][w+1:]
                if((h+1) < h_max):
                    a_tmp[h+1] = a_tmp[h+1][:w] +'#' + a_tmp[h+1][w+1:]
                if((w-1) >= 0):
                    a_tmp[h] = a_tmp[h][:w-1] +'#' + a_tmp[h][w:]
                if((w+1) < w_max):
                    a_tmp[h] = a_tmp[h][:w+1] +'#' + a_tmp[h][w+2:]
        numOfBlack = numOfBlack + a_tmp[h].count('#')
    a = copy.deepcopy(a_tmp)
    result = result + 1

print(result)

Submission status: Wrong Answer

Solution code:
H,W = (int(i) for i in input().split())
e = [list(input()) for i in range(H)]
manhat = [[int(100) for i in range(W)] for j in range(H)]
onon = 100
for tate in range(H):
    for yoko in range(W):
        if e[tate][yoko] == "#":
            for mantate in range(H):
                for manyoko in range(W):
                    if manhat[mantate][manyoko] > abs(mantate-tate) + abs(manyoko-yoko):
                        manhat[mantate][manyoko] = abs(mantate-tate) + abs(manyoko-yoko)
for tate in range(H):
    if onon > max(manhat[tate]):
        onon = max(manhat[tate])
print(onon)

Submission status: Wrong Answer

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

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

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

nl = copy(l)

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

Submission status: Wrong Answer

Solution code:
import copy
n=[int(n) for n in input().split(" ")]
squares=[]
while True:
  try:
  	s=list(input())
  except EOFError:
    break
  squares.append(s)
tmp=copy.deepcopy(squares)
num=0
while True:
  for i in range(n[0]):
    for j in range(n[1]):
      if(squares[i][j]=='#'):
        if(i-1>-1):
          tmp[i-1][j]='#'
        if(i+1<n[0]):
          tmp[i+1][j]='#'
        if(j-1>-1):
          tmp[i][j-1]='#'
        if(j+1<n[1]):
          tmp[i][j+1]='#'
        
  num+=1
  squares=copy.deepcopy(tmp)
  flg=True
  for i in range(n[0]):
    for j in range(n[1]):
      if squares[i][j] != '#':
        flg=False
  if flg:
    break
print(num)

Submission status: Wrong Answer

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

for i in range(h):
    A = list(input())
    for j in range(w):
        a = A[j]
        if a == "#":
            check1[i][j] = 1
        else:
            check1[i][j] = pow(10, 5)

#print(check1)
#for i in range(h):
    for j in range(1, w):
        if check1[i][j - 1] >= 1:
            check1[i][j] = min(check1[i][j - 1] + 1, check1[i][j])

        if check1[i][w - j] >= 1:
            check1[i][w - j - 1] = min(check1[i][w - j] + 1, check1[i][w - j - 1])
ans = 1
#print(check1)
#for j in range(w):
 #   for i in range(1, h):
  #      if check1[i - 1][j] >= 1:
   #         check1[i][j] = min(check1[i - 1][j] + 1, check1[i][j])
#
 #       if check1[h - i][j] >= 1:
  #          check1[h - i - 1][j] = min(check1[h - i][j] + 1, check1[h - i - 1][j])
   #     ans = max(ans, check1[i][j])

#print(check1)
print(ans - 1)

Submission status: Wrong Answer

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

M = {};

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


#print(M)

count = 0

#flg = False

import copy

while True:
    #flg = False

    #temp = [x[:] for x in M]

    temp = copy.deepcopy(M)

    count += 1

    prev = ""

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

            if temp[h][w] == '#':
                if prev == "#":
                    prev = temp[h][w]
                    continue
                else:
                    prev = temp[h][w]

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

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

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

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

    flg = True

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

        if flg == True:
            break

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

    if flg != True:
        break


print(count)

Submission status: Wrong Answer

Solution code:
#import copy
import random

H, W = map(int, input().split())
#dist_matrix = [[10000] * W for i in range(H)]
black_h_list = []
black_w_list = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      black_h_list.append(i)
      black_w_list.append(j)

#print(black_h_list)
#print(black_w_list)

max_value = 0
for index in range(10000):
  i = int(random.random()*H)
  j = int(random.random()*W)
  min_dist = H+W+2
  for k in range(len(black_h_list)):
    dist = abs(i-black_h_list[k]) + abs(j-black_w_list[k])
    if max_value >= dist:
      min_dist = dist
      break
    elif min_dist > dist:
      min_dist = dist        
  #dist_matrix[i][j] = min_dist
  if max_value < min_dist:
    max_value = min_dist

#print(dist_matrix)
    
print(max_value)

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]
        elif h < (H-1):
            t = hw[h+1][w]
        else:
            t = 1
        hw[h][w] = min([t, hw[h][w]])
        if ans < hw[h][w]:
            ans = hw[h][w]
print(ans+1)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
check1 = [[pow(10, 5) for i in range(w)] for j in range(h)]

for i in range(h):
    A = list(input())
    for j in range(w):
        a = A[j]
        if a == "#":
            check1[i][j] = 1
        else:
            check1[i][j] = pow(10, 5)

#print(check1)
#for i in range(h):
    for j in range(1, w):
        if check1[i][j - 1] >= 1:
            check1[i][j] = min(check1[i][j - 1] + 1, check1[i][j])

        if check1[i][w - j] >= 1:
            check1[i][w - j - 1] = min(check1[i][w - j] + 1, check1[i][w - j - 1])
ans = 1
#print(check1)
#for j in range(w):
 #   for i in range(1, h):
  #      if check1[i - 1][j] >= 1:
   #         check1[i][j] = min(check1[i - 1][j] + 1, check1[i][j])
#
 #       if check1[h - i][j] >= 1:
  #          check1[h - i - 1][j] = min(check1[h - i][j] + 1, check1[h - i - 1][j])
   #     ans = max(ans, check1[i][j])

#print(check1)
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import copy

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

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

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
import copy

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

ans = 0

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