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: Runtime Error

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

Submission status: Runtime Error

Solution code:
h, w = [int(i) for i in input().split()]
grid = []
white_num = 0
search_queue = []

for i in range(h):
    row = list(input())
    grid.append(row)
    white_num += row.count('.')
    for j,c in enumerate(row):
        if c == '#':
            search_queue.append([i,j])

iter_num = 0
direction = [[0,-1], [0,1], [1,0], [-1,0]]
while(white_num>0):
    iter_num += 1
    post_queue = []
    for point in search_queue:
        for d in direction:
            if not(0<=point[0]+d[0]<w and 0<=point[1]+d[1]<h):
                continue
            if grid[point[0]+d[0]][point[1]+d[1]] == '.':
                grid[point[0]+d[0]][point[1]+d[1]] = '#'
                white_num -= 1
                post_queue.append([point[0]+d[0], point[1]+d[1]])
    search_queue = post_queue.copy()
    # break

print(iter_num)

Submission status: Runtime Error

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

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


M = [[1000000 for _ in range(W)]  for _ in range(W)]

def get(h,w):
    if h < 0 or H <= h:
        return 1000000
    if w < 0 or W<= w :
        return 1000000
    else:
        return M[h][w]
def get_all(h,w):
    return min([get(h-1,w),get(h+1,w),get(h,w-1),get(h,w+1)])

for i in range(2050):
    for h in range(H):
        for w in range(W):
            if i==0:
                if A[h][w] == "#":
                    M[h][w] = 0
                continue
            if M[h][w] < 2040:
                continue
            # print(i,h,w,get_all(h,w),M)
            if i==get_all(h,w)+1:
                M[h][w] = i


print(max([max(l) for l in M]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(){
    vector<int> dir({0, 1, 0, -1, 0});
    size_t H, W;
    cin >> H >> W;
    vector<vector<short>> dist(H, vector<short>(W, 9999));
    queue<pair<int, int>> q;
    for(size_t i = 0; i < H; ++i){
        string s;
        cin >> s;
        for(size_t j = 0; j < W; ++j){
            if(s[j] & 1){
                dist[i][j] = 0;
                q.emplace(i, j);
            }
        }
    }
    while(!q.empty()){
        auto t = q.front();
        q.pop();
        auto d = dist[t.first][t.second];
        for(size_t i = 0; i < 4; ++i){
            auto x = t.first + dir[i], y = t.second + dir[i + 1];
            if(0 <= x && x < H && 0 <= y && y < W && dist[x][y] > d + 1){
                dist[x][y] = d + 1;
                q.emplace(x, y);
            }
        }
    }
    vector<short> mx;
    transform(dist.begin(), dist.end(), back_inserter(mx), [](auto a){return *max_element(a.begin(), a.end());});
    cout << *max_element(mx.begin(), mx.end()) << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
for i in range(H):
  A = list(map(int,input().split()))