Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

3



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


Sample output:
2

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
A = []
for i in range(H):
    A.append([])
for i in range(H):
    A[i] = list(input())
found = False
k = -1
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] == "#":
                            A[i][j] = 1
                    elif j == W-1:
                        if A[i+1][j] == "#" or A[i][j-1] == "#":
                            A[i][j] =1
                    else:
                        if A[i][j-1] == "#" or A[i][j+1] == "#" or A[i+1][j] == "#":
                            A[i][j] = 1
                elif i == H-1:
                    if j == 0:
                        if A[i-1][j] =="#" or A[i][j+1] == "#":
                            A[i][j] = 1
                    elif j == W-1:
                        if A[i-1][j] == "#" or A[i][j-1] == "#":
                            A[i][j] = 1
                    else:
                        if A[i][j-1] == "#" or A[i][j+1] == "#" or A[i-1][j] == "#":
                            A[i][j] = 1
                elif j == 0:
                    if A[i+1][j] == "#" or A[i][j+1] == "#" or A[i-1][j] == "#":
                            A[i][j] = 1
                elif j == W-1:
                    if A[i+1][j] == "#" or A[i][j-1] == "#" or A[i-1][j] == "#":
                            A[i][j] = 1
                else:
                    if A[i+1][j] == "#" or A[i][j-1] == "#" or A[i-1][j] == "#" or A[i][j+1] == "#":
                            A[i][j] =1 
                        
    print(A)
    for i in range(H):
        for j in range(W):
            if A[i][j] == 1:
                A[i][j] = "#"
print(k)

Submission status: Wrong Answer

Solution code:
from sys import stdin

h, w = [int(x) for x in stdin.readline().rstrip().split()]
board = [[0 for i in range(w)] for j in range(h)]

for j in range(h):
  s = stdin.readline().rstrip()
  for i in range(w):
    if(s[i]=='#'):
      board[j][i] = 1

n=0
maxn = max(h,w)
for n in range(maxn):
  break_flag = 1
  for j in range(h):
    for i in range(w):
      if( board[j][i] != 0):
        continue
      if(0<i and board[j][i-1] == n+1):
        board[j][i] = n+2
      elif(i<(w-1) and board[j][i+1] == n+1):
        board[j][i] = n+2
      elif(0<j and board[j-1][i] == n+1):
        board[j][i] = n+2
      elif(j<(h-1) and board[j+1][i] == n+1):
        board[j][i] = n+2
      else:
        break_flag = 0
  if (break_flag != 0 ):
    break

#print(board)
print(n+1)

Submission status: Wrong Answer

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

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

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


#print(check1)
print(ans - 1)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
whites = set()
blacks = set()
masses = [input() for _ in range(H)]
for h in range(H):
    mas = masses[h]
    for w in range(W):
        if mas[w] == '.':
            whites.add((h, w))
        elif mas[w] == '#':
            blacks.add((h, w))
            if not h-1<0:
                blacks.add((h - 1, w))
            if not h+1>H-1:
                blacks.add((h + 1, w))
            if not w-1<0:
                blacks.add((h, w - 1))
            if not h-1>H-1:
                blacks.add((h, w + 1))
        else:
            print('error:',mas[h])

whites = whites - (whites & blacks)

if len(whites) == 0:
    print('1')
    exit(0)

count=1
while len(whites):
    states=set()
    for blackmas in blacks:
        h=blackmas[0]
        w=blackmas[1]
        if not h - 1 < 0:
            states.add((h - 1, w))
        if not h + 1 > H - 1:
            states.add((h + 1, w))
        if not w - 1 < 0:
            states.add((h, w - 1))
        if not h - 1 > H - 1:
            states.add((h, w + 1))
    blacks = blacks.union(states)
    whites = whites - (whites & blacks)
    count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import copy

def main():
    s_list = input().split()
    h = int(s_list[0])
    w = int(s_list[1])
    a = []
    for i in range(h):
        a.append(list(input()))
    state_a = copy.deepcopy(a)
    n = 0
    while(True):
        is_all = True
        for i in range(h):
            for j in range(w):
                if a[i][j] == '#':
                    try:
                        state_a[i-1][j] = '#'
                    except:
                        pass
                    try:
                        state_a[i][j-1] = '#'
                    except:
                        pass
                    try:
                        state_a[i][j+1] = '#'
                    except:
                        pass
                    try:
                        state_a[i+1][j] = '#'
                    except:
                        pass
                else:
                    is_all = False
        
        a = copy.deepcopy(state_a)
        if is_all:
            print(n)
            break
        n+=1

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
A = [[i for i in input()] for _ in range(H)]
field = [[i+j for i in range(W)] for j in range(H)]
black = []
d = []
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            black.append(i+j)
#0~(H+W-2)
for i in range(H+W-1):
    d.append(min([abs(i-p) for p in black]))
print(max(d))

Submission status: Wrong Answer

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

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


ans = 0
#print(check1)
print(ans - 1)

Submission status: Wrong Answer

Solution code:
def solve():
    H, W = map(int, input().split())
    mass = [[0] * W for _ in range(H)]
    import pprint
    pprint.pprint(mass)
    for Hi in range(H):
        massHi = [0 if s == '.' else 1 for s in list(input())]
        for Wi in range(W):
            mass[Hi][Wi] = massHi[Wi]

    # import pprint
    # pprint.pprint(mass)

    result = 0
    for Hi in range(H):
        for Wi in range(W):
            if mass[Hi][Wi] == 1:
                break
            sub_result = 100000
            for Hi2 in range(H):
                for Wi2 in range(W):
                    if mass[Hi2][Wi2] == 1:
                        sub_result = min(sub_result,
                                         abs(Hi2 - Hi) + abs(Wi2 - Wi))
            result = max(result, sub_result)
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
A=[]
isa=0
jsa=0
HH=99999
WW=99999
for i in range(H):
    x=list(input())
    xc=x.count('#')
    A.append(x)
    if(xc<=HH):
        HH=xc
        isa=i

for i in range(W):
    yc=[row[i] for row in A].count('#')
    if(yc<=WW):
        WW=yc
        jsa=i
    ansj=-1
    ansi=0
for ii in range(H):
    indexes=[i for i, z in enumerate(A[ii]) if z=='#']
    indexes.append(0)
    mx=max(indexes)
    if(ansj<mx):
        ansj=mx
        ansi=ii
print(abs(ansi-isa)+abs(ansj-jsa))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *

nums = []
for i in list(input().split()):
  nums.append(int(i))

#print(nums)

fields = []
for i in range(nums[0]):
	n = []
	words = list(input())
	for j in range(nums[1]):
		if words[j] == '#':
			n.append(1)
		else:
			n.append(0)
	fields.append(n)

#print(fields)

count = 0
while True:
	changed = 0
	c_field = fields[:]
	for i in range(nums[0]):
		for j in range(nums[1]):
			if fields[i][j] == 1:
				if 0 < i:
					if fields[i-1][j] == 0:
						c_field[i-1][j] = 2
						changed = 1

				if i < nums[0]-1:
					if fields[i+1][j] == 0:
						c_field[i+1][j] = 2
						changed = 1

				if 0 < j:
					if fields[i][j-1] == 0:
						c_field[i][j-1] = 2
						changed = 1

				if j < nums[1]-1:
					if fields[i][j+1] == 0:
						c_field[i][j+1] = 2
						changed = 1

	fields = c_field

	#print(fields)

	if changed:
		count = count + 1
	else:
		break

print(count)

Submission status: Wrong Answer

Solution code:
#import copy
import sys
 
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)

if len(black_h_list) == H*W:
  print(0)
  sys.exit()
  
max_value = 1
for i in range(H):
  for j in range(W):
    min_dist = H+W+2
    for k in range(len(black_h_list)):
      if black_h_list[k]-i > min_dist:
        continue
      elif i-black_h_list[k] > min_dist:
        break
      
      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:
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *

nums = []
for i in list(input().split()):
  nums.append(int(i))

#print(nums)

fields = []
for i in range(nums[0]):
	n = []
	words = list(input())
	for j in range(nums[1]):
		if words[j] == '#':
			n.append(1)
		else:
			n.append(0)
	fields.append(n)

#print(fields)

count = 0
while True:
	changed = 0
	c_field = fields[:]
	for i in range(nums[0]):
		for j in range(nums[1]):
			if fields[i][j] == 1:
				if 0 < i:
					if fields[i-1][j] == 0:
						c_field[i-1][j] = 2
						changed = 1

				if i < nums[0]-1:
					if fields[i+1][j] == 0:
						c_field[i+1][j] = 2
						changed = 1

				if 0 < j:
					if fields[i][j-1] == 0:
						c_field[i][j-1] = 2
						changed = 1

				if j < nums[1]-1:
					if fields[i][j+1] == 0:
						c_field[i][j+1] = 2
						changed = 1

	field = c_field

	#print(fields)

	if changed:
		count = count + 1
	else:
		break

print(count)

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H, W):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    tmp = ['#'*(W+2)]
    tmp = tmp + ['#' + read()[:-1] + '#' for _ in range(H)]
    tmp = tmp + ['#' * (W + 2)]
    return tmp


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


H, W = read_ints()
A = read_map(H, W)


# print(A)

from itertools import product


# 開始地点
start = []
for i, a in enumerate(A):
    for j, aa in enumerate(a):
        if aa == '#':
            start.append((i, j))


def mahattan(sy, sx, ey, ex):
    return abs(sy - ey) + abs(sx - ex)


ans = 0
for i, j in product(range(H + 2), range(W + 2)):
    if A[i][j] == '.':
        tmp = 10000
        for ey, ex in start:
            tmp = min(tmp, mahattan(i, j, ey, ex))
        ans = max(ans, tmp)

print(ans+1)

Submission status: Wrong Answer

Solution code:
def solve():
    H, W = map(int, input().split())
    mass = [[0] * W for _ in range(H)]
    import pprint
    pprint.pprint(mass)
    for Hi in range(H):
        massHi = [0 if s == '.' else 1 for s in list(input())]
        print(massHi)
        for Wi in range(W):
            mass[Hi][Wi] = massHi[Wi]

    import pprint
    pprint.pprint(mass)

    result = 0
    for Hi in range(H):
        for Wi in range(W):
            if mass[Hi][Wi] == 1:
                break
            sub_result = 100000
            for Hi2 in range(H):
                for Wi2 in range(W):
                    if mass[Hi2][Wi2] == 1:
                        sub_result = min(sub_result,
                                         abs(Hi2 - Hi) + abs(Wi2 - Wi))
            result = max(result, sub_result)
    print(result)


if __name__ == '__main__':
    solve()

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:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length:
    	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:
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 = 2000
    for l in range(black):
      k=abs(li[l][0]-j)+abs(li[l][1]-i)
      if k == max:
        continue
      if k <= min:
        min = k
    if min >= max:
      max = min
    
print(max)

Submission status: Wrong Answer

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


black=[]

for i in range(h):
    for j  in range(w):
        if li[i][j]=="#":
            black+=([i,j],[i-1,j-1],[i+1,j-1],[i-1,j+1],[i+1,j+1])
            
        
def check(li,i,j,black,count):
    v=[]
    for k in black:
        if abs(k[0]-i)+abs(k[1]-j)<=count:
            return(abs(k[0]-i)+abs(k[1]-j)-count)
        else:
            v.append(abs(k[0]-i)+abs(k[1]-j))
            
 #   print(min(v))
    return min(v)
    
        
        
    

count=0

for i in range(h):
    for j  in range(w):
        if li[i][j]==".":
        
            dist=check(li,i,j,black,count)
            count=max(count,dist)
            

            
            
print(count+1)

Submission status: Wrong Answer

Solution code:
def md(i, j, p):
    return abs(i - p[0]) + abs(j - p[1])

def check(i, j, p):
    ru = 2 * (p[0] - i) + i
    ld = 2 * (p[1] - j) + j
    for k in range(i, min(ru, H)):
        for l in range(j, min(ld, W)):
            check_log[k][l] = True

H, W = map(int, input().split())
lines = []
for i in range(H):
    lines.append(input())
sharps = []
for i, line in enumerate(lines):
    for j, char in enumerate(line):
        if char == '#':
            sharps.append((i, j))

max_d = 0
check_log = [[False] * W] * H

for i in range(H):
    for j in range(W):
        if check_log[i][j]:
            continue
        point_min = 10 ** 10
        for p in sharps:
            temp = md(i, j, p)
            if point_min > temp:
                point_min = temp
                pivot = p
        check(i, j, pivot)
        if point_min > max_d:
            max_d = point_min

print(max_d)

Submission status: Wrong Answer

Solution code:
import copy

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

A= []

for _ in range(H):
    A.append(list(input()))

B = copy.deepcopy(A)

countN = 0

for C in range(100):
    count = 0
    for i in range(H):
        if "." in A[i]:
          for j in range(W):
            if A[i][j] == "#":
                if i != H-1:
                    B[i+1][j] = "#"
                if i != 0:
                    B[i-1][j] = "#"
                if j != 0:
                    B[i][j-1] = "#"
                if j != W-1:
                    B[i][j+1] = "#"
            else:
                count += 1
        else:
            break
    A = copy.deepcopy(B)
    if count != 0:
        countN += 1
    else:
        print(countN)
        break

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:
  cnt = cnt + 1
  flg = 1
  for ih in range(h):
    for iw in range(w):
      tmp_cell = ''
      if arr[ih][iw] == '#':
        arr_next[ih][iw] = '#'
      elif (ih - 1 >= 0 and arr[ih - 1][iw] == '#') + (ih + 1 < h and arr[ih + 1][iw] == '#') + (iw - 1 >= 0 and arr[ih][iw - 1] == '#') + (iw + 1 < w and arr[ih][iw + 1] == '#') > 0:
        arr_next[ih][iw] = '#'
  for ih in range(h):
    if '.' in arr_next[ih]:
      flg = 0
      break
  arr = copy.deepcopy(arr_next)

print(cnt)

Submission status: Wrong Answer

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

M = {};

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

#print(M)

count = 0

flg = True

import copy

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

temp = copy.deepcopy(M)

while flg:
    count += 1

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

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

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

        if flg == True:
            break


print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w = [int(i) for i in input().split()]
c = np.full((h, w), 10000)
# c = [[float("inf") for _ in range(w)] for _ in range(h)]
for i in range(h):
    _a = input()
    for j in range(w):
        if _a[j] == "#":
            c[i, j] = 0


def right():
    for i in range(h):
        for j in range(1, w):
            c[i, j] = min(c[i, j], c[i, j - 1] + 1)


def down():
    for i in range(1, h):
        for j in range(w):
            c[i, j] = min(c[i, j], c[i - 1, j] + 1)


def left():
    for i in range(h):
        for j in reversed(range(w - 1)):
            # if c[i][j + 1] != -1:
            c[i, j] = min(c[i, j], c[i, j + 1] + 1)


def up():
    # _max = 0
    for i in reversed(range(h - 1)):
        for j in range(w):
            # if c[i+1][j] != -1:
            # tmp = min(c[i, j], c[i + 1, j] + 1)
            c[i, j] = min(c[i, j], c[i + 1, j] + 1) # tmp
            # _max = max(_max, tmp)
    # _max = max(_max, max(c[-1]))
    # return _max


right()
left()
down()
up()
# _max = 0
# print(c)
print(c.max())
# _max = max(_max, max(c[i]))
# print(_max)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
tmp = []
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            tmp.append(str(i) + str(j))
if len(tmp) == H * W:
    print(0)
else:
    ans = 0
    for i in range(H):
        for j in range(W):
            if a[i][j] == '.':
                tmp2 = []
                for k in tmp:
                    tmp2.append(abs(int(k[0]) - i) + abs(int(k[1]) - j))
                    if tmp2[-1] <= ans:
                        break
                if min(tmp2) > ans:
                    ans = min(tmp2)
    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:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length:
    	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(area)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

grid = [list(input()) for _ in range(h)]
black = set()
count = 0

for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            black.add((i, j))

def get_arounds(t, h, w):
    arounds = {(t[0] - 1, t[1]),
               (t[0] + 1, t[1]),
               (t[0], t[1] - 1),
               (t[0], t[1] + 1)}
    return set(filter(lambda x: 0 <= x[0] < h and 0 <= x[1] < w, arounds))

while len(black) < h * w:
    print(black)
    count += 1
    black = reduce(lambda acc, x: acc | get_arounds(x, h, w), black, black)

print(count)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

grid = [list(input()) for _ in range(h)]
black = set()
count = 0

for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            black.add((i, j))

def get_arounds(t, h, w):
    arounds = {(t[0] - 1, t[1]),
               (t[0] + 1, t[1]),
               (t[0], t[1] - 1),
               (t[0], t[1] + 1)}
    return set(filter(lambda x: 0 <= x[0] < h and 0 <= x[1] < w, arounds))

while len(black) < h * w and count < 10:
    print(black)
    count += 1
    black = reduce(lambda acc, x: acc | get_arounds(x, h, w), black, black)

print(count)

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'
    
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:
h,w = map(int,input().split())
list1 = ["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(w+2)]
cnt = 0
maxcnt = 0
for j in range(h+1):
  for k in range(w+1):
    if list1[j][k] == '.' and cnt == 0:
      cnt+=1
    if list1[j][k-1]=='.' and list1[j][k+1]=='.' and list1[j+1][k]=='.' and list1[j-1][k]=='.':
      if j != 0 and k != 0:  
        cnt+=1
        lj=j
        lk=k
        flag=0
        while flag==0 and lj<h and lk<w:
          if list1[lj+1][lk+1]!='#' and list1[lj-1][lk-1]!='#':
            cnt+=1
          else:
            flag==1
            if cnt > maxcnt:
              maxcnt = cnt
            cnt = 0
            str_list = list(list1[j])
            str_list[k] = '#'
            list1[j] = str_list
            break;
          lj+=1
          lk+=1
    else:
      if cnt > maxcnt:
        maxcnt = cnt
      cnt = 0
print(maxcnt)

Submission status: Wrong Answer

Solution code:
def dark(i,j):
    h = len(mas)
    w = len(mas[0])
    x = 0
    if i != h-1:
        if mas[i+1][j] != "#":
            #mas[i+1][j] = "#"
            dk.append([i+1,j])
            x += 1
    if i != 0:
        if mas[i-1][j] != "#":
            #mas[i-1][j] = "#"
            dk.append([i-1,j])
            x += 1
    if j != w-1:
        if mas[i][j+1] != "#":
            #mas[i][j+1] = "#"
            dk.append([i,j+1])
            x += 1
    if j != 0:
        if mas[i][j-1] != "#":
            #mas[i][j-1] = "#"
            dk.append([i,j-1])
            x += 1
    return x

h,w = map(int,input().split())
mas = [[0 for i in range(w)] for j in range(h)]
dk = []
for i in range(h):
    tmp = list(input())
    for j in range(w):
        if tmp[j] == "#":
            dk.append([i,j])
        mas[i][j] = tmp[j]

#print(dk)
res = 0
l = len(dk)
while l < w*h:
    dkl = len(dk)
    for i in range(dkl):
        l += dark(dk[i][0],dk[i][1])
    del dk[:dkl]
    
    #pprint.pprint(mas)
    res += 1
    #print(len(dk))

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque
h,w = map(int, input().split(' '))
NLIST = []
for i in range(h):
    _w = list(input())
    for j in range(w):
        c = _w[j]
        if c == '#':
            NLIST.append( (i, j) )

res = 0
for p in [(0,0), (h-1,0), (0,w-1), (h-1, w-1)]:
    tmp = 10000
    for q in NLIST:
        distance = abs( p[0] - q[0] ) + abs( p[1] - q[1] )
        tmp = min( tmp, distance )
    res = max(res, tmp) 
print(res)

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)
print(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:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length:
    	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:
import numpy as np
h, w = map(int,input().split())
grid = np.array([list(input()) for _ in range(h)])

large_grid = np.array([["." for _ in range(w+2)] for _ in range(h+2)])
goal_grid = [["#" for _ in range(w)] for _ in range(h)]
cnt = 0
while True:
    for row in range(h):
        for col in range(w):
            if grid[row][col] == "#":
                large_grid[row][col+1] = "#"
                large_grid[row+2][col+1] = "#"
                large_grid[row+1][col+1] = "#"
                large_grid[row+1][col+2] = "#"
                large_grid[row+1][col] = "#"

    grid3 = large_grid[1:h+1, 1:w+1]
    #grid = grid3#参照元とかの問題でバグる
    grid = np.copy(grid3)
    cnt +=1
    #print(grid)
    if (grid == goal_grid).all():
        break
print(cnt)

#     grid = grid2
#     print(grid2)
#     print(grid)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
dp=[[10000]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      for k in range(h):
        dp[k][j]=min(dp[k][j],abs(k-i))
      for k in range(w):
        dp[i][k]=min(dp[i][k],abs(k-j))
for i in range(h):
  for j in range(w):
    if dp[i][j]==10000:
      tmp=[dp[k][j]+abs(k-i) for k in range(h)]
      tmp.extend([dp[i][k]+abs(k-j) for k in range(w)])
      dp[i][j]=min(tmp)
print(np.max(dp))

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:
    	area[target_index - 1] = '#'
    # 右方向
    if target_index + 1 < area_length:
    	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

Submission status: Wrong Answer

Solution code:
import copy
import sys

H,W=[int(i) for i in input().split(" ")]

board=[[100000 for i in range(W+2)]]

def cod2num(i):
    if i==".":
        return 100000
    else:
        return 0

for i in range(H):
    line=[100000]+[cod2num(j) for j in input()]+[100000]
    board.append(line)
board.append([100000 for i in range(W+2)])



while True:
    M=0
    for i in range(1,H+1):
        for j in range(1,W+1):
            board[i][j]=min(board[i][j],board[i-1][j]+1,board[i+1][j]+1,board[i][j-1]+1,board[i][j+1]+1)
            M=max(M,board[i][j])
    if M<100000:
        print(M)
        sys.exit()