Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

3



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


Sample output:
2

Submission status: Wrong Answer

Solution code:
import copy

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 min(a[_h][max(0,_w-1)], a[_h][min(w-1,_w+1)], a[max(0,_h-1)][_w], a[min(h-1,_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

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)
visited = [[True]*(W+2)]
visited.extend([[True] + [False] * W + [True] for _ in range(H)])
visited.append([True]*(W+2))  # 無駄な探索を省くため
from itertools import product
from collections import deque
# print(visited)
# 開始地点
start = []
for i, a in enumerate(A):
    if i == 0 or i == H + 1:
        continue
    for j, aa in enumerate(a):
        if j == 0 or j == W + 1:
            continue
        if aa == '#':
            start.append((i, j))

# 探索の準備
mvx = (1, 0, -1, 0)
mvy = (0, 1, 0, -1)


# distlist = []

# for si, sj in start:
n_white = (W)*(H)
# visited = [[False] * (W+2) for _ in range(H+2)]
que = deque([(si, sj, 0) for si, sj in start])
for si, sj in start:
    n_white -= 1
    visited[si][sj] = True

# 幅優先探索
while que:
    y, x, cost = que.popleft()

    if n_white <= 0:
        ans = cost
        break
    for dy, dx in zip(mvy, mvx):
        y_new, x_new = y + dy, x + dx
        # 探索に含めない条件
        if not (-1 < y_new < H+2) or not (-1 < x_new < W+2):
            continue
        if visited[y_new][x_new]:
            continue

        # 探索に追加してあげる
        que.append((y_new, x_new, cost + 1))
        visited[y_new][x_new] = True
        n_white -= 1
        if n_white == 0:
            ans = cost + 1
            break

    # A[si][sj] = '#'
print(ans+1)

Submission status: Wrong Answer

Solution code:
import copy
H,W = input().split()
H = int(H)
W = int(W)
A = []
for i in range(H):
    A.append(input())

MAX = 10000000000000

L = []
L.append([MAX for i in range(W+2)])
toCheck = []
for i in range(H):
    L.append([MAX])
    for j in range(W):
        if A[i][j]=='#':
            L[i+1].append(0)
            toCheck.append((i+1,j+1))
        else:
            L[i+1].append(MAX)
    L[i+1].append(MAX)
L.append([MAX for i in range(W+2)])

while(True):
    print(toCheck)
    toCheck_new = []
    if len(toCheck)==0: break
    for (i,j) in toCheck:
        if L[i-1][j] > L[i][j]+1 and i-1!=0:
            L[i-1][j] = L[i][j]+1
            toCheck_new.append((i-1,j))
        if L[i+1][j] > L[i][j]+1 and i+1!=H+1:
            L[i+1][j] = L[i][j]+1
            toCheck_new.append((i+1,j))
        if L[i][j-1] > L[i][j]+1 and j-1!=0:
            L[i][j-1] = L[i][j]+1
            toCheck_new.append((i,j-1))
        if L[i][j+1] > L[i][j]+1 and j+1!=W+1:
            L[i][j+1] = L[i][j]+1
            toCheck_new.append((i,j+1))
    if len(toCheck_new)==0: break
    toCheck = copy.copy(toCheck_new)

maximum = 0
for i in range(1,H+1):
    _ = max(L[i][1:W+1])
    if maximum<_:
        maximum = _

print(maximum)

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 = 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:
#for i in range(1000):
#    print("."*499+"#"+"."*500)
#exit()
h,w=map(int,input().split())
#l=[list(input()) for i in range(h)]
l=[]
d=set()
for i in range(h):
    s=list(input())
    for j in range(w):
        if s[j]=="#": d.add((i,j))
    l.append(s)
ans=-1
for i in range(1000):
    if len(d)==0: break
    ans+=1
    t=set()
    for j in d:
        #print(j)
        if 0<=j[0]+1<h and l[j[0]+1][j[1]]==".":
            l[j[0]+1][j[1]]="#"
            t.add((j[0]+1,j[1]))
        if 0<=j[0]-1<h and l[j[0]-1][j[1]]==".":
            l[j[0]-1][j[1]]="#"
            t.add((j[0]-1,j[1]))
        if 0<=j[1]+1<w and l[j[0]][j[1]+1]==".":
            l[j[0]][j[1]+1]="#"
            t.add((j[0],j[1]+1))
        if 0<=j[1]-1<w and l[j[0]][j[1]-1]==".":
            l[j[0]][j[1]-1]="#"
            t.add((j[0],j[1]-1))
    d=t
print(ans)

Submission status: Wrong Answer

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

row_indices = []
white_cols = 0
for i in range(H):
    last_cols = 0
    indices = []
    while True:
        cols = A[i].find('#', last_cols)
        if cols < 0:
            if last_cols > 0:
                white_cols = max(white_cols, len(A[i]) - last_cols)
            row_indices.append(indices)
            break
        else:
            white_cols = max(white_cols, cols - last_cols)
            last_cols = cols + 1
            indices.append(cols)

white_rows = 0
last_idx = 0
for i, indices in enumerate(row_indices):
    if len(indices):
        white_rows = max(white_rows, i - last_idx)
        last_idx = i + 1
    if i == H - 1:
        white_rows = max(white_rows, H - last_idx)

print(white_cols + white_rows)

Submission status: Wrong Answer

Solution code:
import copy
H,W = input().split()
H = int(H)
W = int(W)
A = []
for i in range(H):
    A.append(input())

MAX = 10000000000000

L = []
L.append([MAX for i in range(W+2)])
toCheck = []
for i in range(H):
    L.append([MAX])
    for j in range(W):
        if A[i][j]=='#':
            L[i+1].append(0)
            toCheck.append((i+1,j+1))
        else:
            L[i+1].append(MAX)
    L[i+1].append(MAX)
L.append([MAX for i in range(W+2)])

while(True):
    print(toCheck)
    toCheck_new = []
    if len(toCheck)==0: break
    for (i,j) in toCheck:
        if L[i-1][j] > L[i][j]+1:
            L[i-1][j] = L[i][j]+1
            if i-1!=0: 
                toCheck_new.append((i-1,j))
        if L[i+1][j] > L[i][j]+1:
            L[i+1][j] = L[i][j]+1
            if i+1!=H+2:
                toCheck_new.append((i+1,j))
        if L[i][j-1] > L[i][j]+1:
            L[i][j-1] = L[i][j]+1
            if j-1!=0:
                toCheck_new.append((i,j-1))
        if L[i][j+1] > L[i][j]+1:
            L[i][j+1] = L[i][j]+1
            if j+1!=W+2:
                toCheck_new.append((i,j+1))
    if len(toCheck_new)==0: break
    tocheck = copy.copy(toCheck_new)

maximum = 0
for i in range(1,H+1):
    _ = max(L[i][1:W+1])
    if maximum<_:
        maximum = _

print(maximum)

Submission status: Wrong Answer

Solution code:
h, w=map(int, input().split())
a=[]
for i in range(h):
    a.append(list(input().split()))
b=[]
for i in range(len(a)):
    b.append(list(a[i][0]))
for i in range(h):
    for j in range(w):
        if b[i][j]==".":
            b[i][j]=0
        elif b[i][j]=="#":
            b[i][j]=1
pos_list=set()
cnt=0
for i in range(1):
    cnt+=1
    for x in range(h):
        for y in range(w):
            if b[x][y]==1:
                pos_list.add((x, y))
                continue
            else:
                pass
    print(pos_list)
    for t in pos_list:
        try:
            b[t[0]-1][t[1]]=1
        except IndexError:
            continue
        try:
            b[t[0]+1][t[1]]=1
        except IndexError:
            continue
        try:
            b[t[0]][t[1]-1]=1
        except IndexError:
            continue
        try:
            b[t[0]][t[1]+1]=1
        except IndexError:
            continue
print(cnt+1)

Submission status: Wrong Answer

Solution code:
H, W = [int(i) for i in input().split()]
nmin_1 = 1000000000000
nmin_2 = 1000000000000
nmin_3 = 1000000000000
nmin_4 = 1000000000000
for i in range(H):
  chars = []
  for j,c in enumerate(input()):
    chars.append(c)
    if c == '#':

      nmin_1 = min(nmin_1, abs(i)+abs(j))
      nmin_2 = min(nmin_2, abs(i)+abs(W-1-j))
      nmin_3 = min(nmin_3, abs(H-1-i)+abs(j))
      nmin_4 = min(nmin_4, abs(H-1-i)+abs(W-1-j))

print (max(nmin_1, max(nmin_2, max(nmin_3, nmin_4))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
A = [list(input()) for i in range(h)]
A_check = [(i,j) for i in range(h) for j in range(w) if A[i][j]=='#']
  
ans = 0
while 1:
  A_check_tmp = []
  for i, j in A_check:
    i_s = max(0,i-1)
    i_l = min(h-1,i+1)
    j_s = max(0,j-1)
    j_l = min(w-1,j+1)
    A[i_s][j]='#'
    A[i_l][j]='#'
    A[i][j_s]='#'
    A[i][j_l]='#'
    if A[i_s][j]=='.':
      A_check_tmp.append((i_s,j))
    if A[i_l][j]=='.':
      A_check_tmp.append((i_l,j))
    if A[i][j_s]=='.':
      A_check_tmp.append((i,j_s))
    if A[i][j_l]=='.':
      A_check_tmp.append((i,j_l))
  A_check = A_check_tmp
  if A_check==[]:  
    break
  ans+=1
 
print(ans)

Submission status: Wrong Answer

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

row_indices = []
white_cols = 0
for i in range(H):
    last_cols = 0
    indices = []
    while True:
        cols = A[i].find('#', last_cols)
        if cols < 0:
            if last_cols > 0:
                white_cols = max(white_cols, len(A[i]) - last_cols)
            row_indices.append(indices)
            break
        else:
            white_cols = max(white_cols, cols - last_cols)
            last_cols = cols + 1
            indices.append(cols)

white_rows = 0
last_idx = 0
for i, indices in enumerate(row_indices):
    if len(indices):
        white_rows = max(white_rows, i - last_idx)
        last_idx = i
    if i == H - 1:
        white_rows = max(white_rows, H - last_idx)

print(white_cols + white_rows)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
import numpy as np
h, w = map(int, input().split())
data = []
for n in range(h):
    data.append(list(input().rstrip()))

bindata1 = np.zeros((h, w), int)

for l, r in [(l, r) for l in range(h) for r in range(w)]:
    if data[l][r] == '#':
        bindata1[l, r] = 1

bindata2 = bindata1.transpose()


count = 0
while bindata1.min() == 0:
    count += 1
    b1_copy = deepcopy(bindata1)
    b1_copy[0] = bindata1[1] | bindata1[0]
    for l in range(h - 1):
        b1_copy[l] = bindata1[l - 1] | bindata1[l] | bindata1[l + 1]
    b1_copy[h - 1] = bindata1[h - 1] | bindata1[h - 2]

    b2_copy = deepcopy(bindata2)
    b2_copy[0] = bindata2[0] | bindata2[1]
    for r in range(w - 1):
        b2_copy[r] = bindata2[r - 1] | bindata2[r] | bindata2[r + 1]
    b2_copy[w - 1] = bindata2[w - 1] | bindata2[w - 2]
    bindata1 = b1_copy | b2_copy.transpose()
    bindata2 = bindata1.transpose()

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

def repl(s):
    if s == '.':
        return 1
    if s == '#':
        return 0
    return

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

list_HW = [list(map(repl, input())) for _ in range(H)]

def operate(list_):
    array = np.array([[1]*W] + list_ + [[1]*W])
    array = array[:H] * array[1:H+1] * array[2:H+2]

    tr_array = np.array(list_).T.tolist()
    tr_array = np.array([[1]*H] + tr_array + [[1]*H])
    tr_array = (tr_array[:W] * tr_array[1:W+1] * tr_array[2:W+2]).T
    
    result = (array + tr_array > 1) * 1
    return result

list_ = list_HW
t = np.array([1])
num = 0
while t.max()>0:
    t = operate(list_)
    list_ = t.tolist()
    num += 1

print(num)

Submission status: Wrong Answer

Solution code:
import copy
from collections import Counter

def is_complete(boad):
    for col in boad:
        if ['.'] in col:
            return False
    return True


def change_around_white_cells(boad, h, w, x, y):
    # 5を中心とした座標の辞書
    index_dic = {1:(-1, 0), 2:(0, -1), 3:(0, 1), 4:(1, 0)}
    # 一番左の列に中心
    if x - 1 < 0:
        index_dic.pop(1)

    # 一番右の列に中心
    if x + 1 >= w:
        index_dic.pop(4)

    # 一番上の行に中心
    if y - 1 < 0:
        index_dic.pop(2)

    # 一番下の行に中心
    if y + 1 >= h:
        index_dic.pop(3)

    for key in index_dic.keys():
        i, j = index_dic[key]
        boad[y + j][x + i] = ['#']

    return boad

def change_around_black_cells(boad, h, w, x, y):
    # 5を中心とした座標の辞書
    index_dic = {1:(-1, 0), 2:(0, -1), 3:(0, 1), 4:(1, 0)}
    # 一番左の列に中心
    if x - 1 < 0:
        index_dic.pop(1)

    # 一番右の列に中心
    if x + 1 >= w:
        index_dic.pop(4)

    # 一番上の行に中心
    if y - 1 < 0:
        index_dic.pop(2)

    # 一番下の行に中心
    if y + 1 >= h:
        index_dic.pop(3)

    for key in index_dic.keys():
        i, j = index_dic[key]
        if boad[y + j][x + i] == ['#']:
            boad[y + j][x + i] = ['#']
            break

    return boad

def check_major(boad):
    all_cell = []
    for b in boad:
        line = ""
        for i in b:
            line += i[0]
        all_cell.append("".join(line))
    all_cell = "".join(all_cell)
    cell_cnt = Counter(list(all_cell))
    if "#" in cell_cnt.most_common()[0]:
        return "#"
    return "."


def main():
    #マス目入力
    input_data = input().split()
    h, w = (int(i) for i in input_data)
    # print(h,w)
    #盤面入力
    boad = []
    for i in range(h):
        boad.append(list(list(i) for i in input()))
    # print(boad)

    new_boad = copy.deepcopy(boad)

    cnt = 0
    complete_flag = is_complete(boad)
    while(not complete_flag):
        cnt += 1
        print(check_major(boad))
        for y, col in enumerate(boad):
            if ['#'] in col:
                indexes = [i for i, d in enumerate(col) if d == ['#']]
                for x in indexes:
                    cell = col[x]
                    if cell == ['#']:
                        new_boad = change_around_white_cells(new_boad, h, w, x, y)
                        complete_flag = is_complete(new_boad)
                        if complete_flag:
                            break
                    if ['#'] not in col[x:]:
                        break
            if complete_flag:
                break

        boad = copy.deepcopy(new_boad)
        # for b in new_boad:
        #     print(b)
        # print("++++++++")
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# H, W = map(int, input().split())
# A = ['' for _ in range(H)]
# for i in range(H):
#     A[i] = input()
# def operation(arr):
#     res = arr.copy()
#     h = len(arr)
#     w = len(arr[0])
#     for i in range(h):
#         if arr[i].find('.') >= 0:
#             for j in range(w):
#                 if res[i].find('.') < 0:
#                     break
#                 if arr[i][j] == '#':
#                     if i - 1 >= 0 and res[i-1][j] != '#':
#                         res[i-1] = res[i-1][:max(j, 0)] + '#' + res[i-1][min(j+1, w):]
#                     if i + 1 < h and res[i+1][j] != '#':
#                         res[i+1] = res[i+1][:max(j, 0)] + '#' + res[i+1][min(j+1, w):]
#                     if j - 1 >= 0 and res[i][j-1] != '#':
#                         res[i] = res[i][:max(j-1, 0)] + '#' + res[i][min(j, w):]
#                     if j + 1 < w and res[i][j+1] != '#':
#                         res[i] = res[i][:max(j+1, 0)] + '#' + res[i][min(j+2, w):]
#     return res
#
#
# cnt = 0
# while True:
#     for i in range(H):
#         if A[i].find('.') >= 0:
#             A = operation(A)
#             cnt += 1
#             break
#     else:
#         break
#
# print(cnt)


# import copy
#
# H, W = map(int, input().split())
# A = [[0 for _ in range(W)] for _ in range(H)]
# for row in range(H):
#     s = input()
#     for col in range(len(s)):
#         A[row][col] = 1 if s[col] == '#' else 0
#
#
# def operation(arr):
#     res = copy.deepcopy(arr)
#     h = len(arr)
#     w = len(arr[0])
#     found = False
#     for i in range(h):
#         for j in range(w):
#             if arr[i][j]:
#                 if i - 1 >= 0 and res[i-1][j] == 0:
#                     res[i-1][j] = 1
#                     found = True
#                 if i + 1 < h and res[i+1][j] == 0:
#                     res[i+1][j] = 1
#                     found = True
#                 if j - 1 >= 0 and res[i][j-1] == 0:
#                     res[i][j-1] = 1
#                     found = True
#                 if j + 1 < w and res[i][j+1] == 0:
#                     res[i][j+1] = 1
#                     found = True
#     return res, found
#
#
# cnt = 0
# while True:
#     A, result = operation(A)
#     if result:
#         cnt += 1
#     else:
#         break
# print(cnt)

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

row_indices = []
white_cols = 0
for i in range(H):
    last_cols = 0
    indices = []
    while True:
        cols = A[i].find('#', last_cols)
        if cols < 0:
            if last_cols > 0:
                white_cols = max(white_cols, len(A[i]) - last_cols)
            row_indices.append(indices)
            break
        else:
            white_cols = max(white_cols, cols - last_cols)
            last_cols = cols + 1
            indices.append(cols)

white_rows = 0
last_idx = 0
for i, indices in enumerate(row_indices):
    if len(indices):
        white_rows = max(white_rows, i - last_idx)
        last_idx = i
    if i == H - 1:
        white_rows = max(white_rows, H - last_idx)

print(white_cols + white_rows)

Submission status: Wrong Answer

Solution code:
a,b=input().split()
a=int(a)
ppap=[]
for i in range(a):
    c=input()
    l=[]
    for i in c:
        l.append(i)
    ppap.append(l)
fl=[]
of=0
while 1:
    cc=0
    for i in ppap:
        for j in i:
            cc+=j.count(".")
    if cc==0:
        break
    for j in ppap:
        x=[i for i,x in enumerate(j) if x=="#"]
        for i in x:
            fl.append([of,i])
        of+=1
    dl=[]
    ofset1=0
    for i in ppap:
        ofset2=0
        for j in i:
            kl=[]
            if j==".":
                for k in fl:
                    x=abs(ofset1-k[0])+abs(ofset2-k[1])
                    kl.append(x)
                dl.append(min(kl))
            ofset2+=1
        ofset1+=1
    print(max(dl))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import copy

intRow, intCol = map(int, input().split())

aryBoard = []
for intIdx in range(intRow):
    aryBoard.append(list(input()))
#print(aryBoard)

totalTurn = 0
boolCheck = True
while boolCheck:
    boolCheck = False

    tmpBoard = copy.copy(aryBoard)
    for idxI in range(intRow):
        #print(aryBoard[idxI])
        for idxJ in range(intCol):
            # マスが黒色の場合、上下左右の白を黒に変える
            if aryBoard[idxI][idxJ] == "#":
                # 左
                if idxJ > 0 and aryBoard[idxI][idxJ - 1] == ".":
                    tmpBoard[idxI][idxJ - 1] = "#"
                    boolCheck = True
                    #print(idxI, idxJ, idxI, idxJ - 1)
                # 右
                if idxJ < intCol - 1 and aryBoard[idxI][idxJ + 1] == ".":
                    tmpBoard[idxI][idxJ + 1] = "#"
                    boolCheck = True
                    #print(idxI, idxJ, idxI, idxJ + 1)
                # 上
                if idxI > 0 and aryBoard[idxI - 1][idxJ] == ".":
                    tmpBoard[idxI - 1][idxJ] = "#"
                    boolCheck = True
                    #print(idxI, idxJ, idxI - 1, idxJ)
                # 下
                if idxI < intRow - 1 and aryBoard[idxI + 1][idxJ] == ".":
                    tmpBoard[idxI + 1][idxJ] = "#"
                    boolCheck = True
                    #print(idxI, idxJ, idxI + 1, idxJ)

    if boolCheck:
        totalTurn += 1

    aryBoard = copy.copy(tmpBoard)
    #print(aryBoard)

print(totalTurn)

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().split()))
def black(x):
  return int(bool(x=='#'))
lst = []
for h in range(H):
  row = input()
  lst += [[]]
  for w in range(W):
    lst[-1] += [black(row[w])]
print(lst)
row = []
for h in range(H):
  row += [max(lst[h])]
print(row)
column = []
for w in range(W):
  tmp = 0
  while True:
    if tmp == H:
      column += [0]
      break
    elif lst[tmp][w] == 1:
      column += [1]
      break
    else:
      tmp += 1
print(column)

Submission status: Wrong Answer

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

import numpy as np

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

print(i)

Submission status: Wrong Answer

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

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

ans=0
sankaku=np.array(np.arange(w,dtype=int))

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

Submission status: Wrong Answer

Solution code:
h, w=map(int, input().split())
a=[]
for i in range(h):
    a.append(list(input().split()))
b=[]
for i in range(len(a)):
    b.append(list(a[i][0]))
for i in range(h):
    for j in range(w):
        if b[i][j]==".":
            b[i][j]=0
        elif b[i][j]=="#":
            b[i][j]=1
pos_list=set()
cnt=0
for i in range(1):
    cnt+=1
    for x in range(h):
        for y in range(w):
            if b[x][y]==1:
                pos_list.add((x, y))
                continue
            else:
                pass
    print(pos_list)
    for t in pos_list:
        try:
            b[t[0]-1][t[1]]=1
        except IndexError:
            continue
        try:
            b[t[0]+1][t[1]]=1
        except IndexError:
            continue
        try:
            b[t[0]][t[1]-1]=1
        except IndexError:
            continue
        try:
            b[t[0]][t[1]+1]=1
        except IndexError:
            continue
print(cnt)

Submission status: Wrong Answer

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

import numpy as np
import copy

mat = np.zeros(h*w).reshape([h,w])

for j in range(h):
    
    dot = input()
    
    for i in range(w):
        mat[j,i] = int(dot[i] == '#')

I, J = np.where(mat==1)

print(min(h+w - (I + J)))

Submission status: Wrong Answer

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

row_indices = []
white_cols = 0
for i in range(H):
    last_cols = 0
    indices = []
    while True:
        cols = A[i].find('#', last_cols)
        if cols < 0:
            if last_cols > 0:
                white_cols = max(white_cols, len(A[i]) - last_cols)
            row_indices.append(indices)
            break
        else:
            white_cols = max(white_cols, cols - last_cols)
            last_cols = cols + 1
            indices.append(cols)

white_rows = 0
last_idx = 0
for i, indices in enumerate(row_indices):
    if len(indices):
        white_rows = max(white_rows, i - last_idx)
    if i == H - 1:
        white_rows = max(white_rows, H - last_idx)

print(white_cols + white_rows)

Submission status: Wrong Answer

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

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

area_length = len(area)
answer = 0

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

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

print(answer)

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 = []
end = []
for i, a in enumerate(A):
    for j, aa in enumerate(a):
        if aa == '#':
            end.append((i, j))
            if i == 0 or i == H + 1 or j == 0 or j == W + 1:
                continue
            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), range(W)):
#     if A[i][j] == '.':
#         tmp = 10000
#         for ey, ex in start:
#             tmp = min(tmp, mahattan(i, j, ey, ex))
#         ans = max(ans, tmp)

for i, j in start:
    tmp1 = 10000
    tmp2 = 10000
    tmp3 = 10000
    tmp4 = 10000

    for ey, ex in end:
        if ey >= i and ex > j:
            tmp1 = min(tmp1, mahattan(i, j, ey, ex))
        elif ey > i and ex <= j:
            tmp2 = min(tmp2, mahattan(i, j, ey, ex))
        elif ey <= i and ex < j:
            tmp3 = min(tmp3, mahattan(i, j, ey, ex))
        else:
            tmp4 = min(tmp4, mahattan(i, j, ey, ex))
        # print(tmp1, tmp2, tmp3, tmp4)
    tmp = max(tmp1, tmp2, tmp3, tmp4)
    ans = max(ans, tmp)

print(ans//2+1)

Submission status: Wrong Answer

Solution code:
li = input().split()
H=int(li[0])
W=int(li[1])
li =[]
 
for j in range(H):
  s=list(input())
  for i in range(W):
      if s[i]=="#" :
        li.append((j,i))

max=0
black=len(li)
for j in range(H):
  for i in range(W):
    min = 1000
    for l in range(black):
      k=abs(li[l][0]-j)+abs(li[l][1]-i)
      if k <= min:
        min = k
      if min <= 0:
        continue
    if min >= max:
      max = min
    
print(max)