Problem:


Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.



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


Sample output:
4

Submission status: Wrong Answer

Solution code:
import collections as cl

def func (h,w,i,j):
    count=0
    ans=[1]
    q=cl.deque()
    q.append([i,j,count])
    ch=[[0 for i in range(w)]for j in range(h)]
    while q:
        i,j,count=q.popleft()
        if i-1>=0 and s[i-1][j]=='.' and ch[i-1][j] == 0:
            q.append([i-1,j,count+1])
            ch[i-1][j] = 1
            ans.append(count+1)
        if i+1 < h and s[i+1][j] == '.' and ch[i+1][j] == 0:
            q.append([i+1,j,count+1])
            ch[i+1][j] = 1
            ans.append(count+1)
        if j-1 >= 0 and s[i][j-1] == '.' and ch[i][j-1] == 0:
            q.append([i,j-1,count+1])
            ch[i][j-1] = 1
            ans.append(count+1)
        if j+1 < w and s[i][j+1] == '.' and ch[i][j+1] == 0:
            q.append([i,j+1,count+1])
            ch[i][j+1] = 1
            ans.append(count+1)

    return max(ans)

h,w=map(int,input().split())
s=[]
ans=0
for i in range(h):
    s.append(list(map(str,input())))

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            a=func(h,w,i,j)
            if ans<a:
                ans=a
        else:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as cl

def func (h,w,i,j):
    count=0
    ans=[]
    q=cl.deque()
    q.append([i,j,count])
    ch=[[0 for i in range(w)]for j in range(h)]
    while q:
        i,j,count=q.popleft()
        if i-1>=0 and s[i-1][j]=='.' and ch[i-1][j] == 0:
            q.append([i-1,j,count+1])
            ch[i-1][j] = 1
            ans.append(count+1)
        if i+1 < h and s[i+1][j] == '.' and ch[i+1][j] == 0:
            q.append([i+1,j,count+1])
            ch[i+1][j] = 1
            ans.append(count+1)
        if j-1 >= 0 and s[i][j-1] == '.' and ch[i][j-1] == 0:
            q.append([i,j-1,count+1])
            ch[i][j-1] = 1
            ans.append(count+1)
        if j+1 < w and s[i][j+1] == '.' and ch[i][j+1] == 0:
            q.append([i,j+1,count+1])
            ch[i][j+1] = 1
            ans.append(count+1)

    return max(ans)

h,w=map(int,input().split())
s=[]
ans=0
for i in range(h):
    s.append(list(map(str,input())))

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            a=func(h,w,i,j)
            if ans<a:
                ans=a
        else:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

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

ans = 0

#startを順に探索
for y in range(h):
    for x in range(w):
    
        i = 0
        move = [[-1] * w for _ in range(h)]
        print(x, y)
        #壁はスキップ
        if(maze[y][x] == '#'):
            continue

        #幅優先探索
        q = queue.Queue()
        q.put([x, y])
        move[y][x] = 0

        while not q.empty():
            pos = q.get()
            for i in range(4):
                next = [pos[0] + dx[i], pos[1] + dy[i]]

                #端
                if(next[0] == w or next[1] == h or next[0] < 0 or next[1] < 0):
                    continue

                if(maze[next[1]][next[0]] == '.' and move[next[1]][next[0]] == -1):
                    move[next[1]][next[0]] = move[pos[1]][pos[0]] + 1
                    q.put(next)
        ans = max([ans] + [max(v) for v in move])

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list('#' * (W + 2))]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))

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

inf = float('inf')

N = W * H
l = [[inf] * N for _ in range(N)]

for w in range(1, W + 1):
    for h in range(1, H + 1):
        if S[h][w] != '#':
            l[(h - 1) * W + w - 1][(h - 1) * W + w - 1] = 0
            for x, y in zip(dx, dy):
                if S[h + y][w + x] != '#':
                    l[(h - 1) * W + w - 1][(h + y - 1) * W + w + x - 1] = 1

ans = -1

for k in range(N):
    for i in range(N):
        for j in range(N):
            tmp = min(l[i][j], l[i][k] + l[k][j])
            if tmp != inf:
                ans = max(ans, tmp)
            l[i][j] = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list('#' * (W + 2))]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))

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

inf = float('inf')

N = W * H
l = [[inf] * N for _ in range(N)]

for w in range(1, W + 1):
    for h in range(1, H + 1):
        if S[h][w] != '#':
            l[(h - 1) * W + w - 1][(h - 1) * W + w - 1] = 0
            for x, y in zip(dx, dy):
                if S[h + y][w + x] != '#':
                    l[(h - 1) * W + w - 1][(h + y - 1) * W + w + x - 1] = 1

ans = -1

# for k in range(N):
#     for i in range(N):
#         for j in range(N):
#             tmp = min(l[i][j], l[i][k] + l[k][j])
#             if tmp != inf:
#                 ans = max(ans, tmp)
#             l[i][j] = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list('#' * (W + 2))]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))

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

inf = float('inf')

N = W * H
l = [[inf for _ in range(N)] for _ in range(N)]

for w in range(1, W + 1):
    for h in range(1, H + 1):
        if S[h][w] != '#':
            l[(h - 1) * W + w - 1][(h - 1) * W + w - 1] = 0
            for x, y in zip(dx, dy):
                if S[h + y][w + x] != '#':
                    l[(h - 1) * W + w - 1][(h + y - 1) * W + w + x - 1] = 1

for i in range(N):
    for j in range(N):
        for k in range(N):
            l[i][j] = min(l[i][j], l[i][k] + l[k][j])

for i in range(N):
    for j in range(N):
        for k in range(N):
            l[i][j] = min(l[i][j], l[i][k] + l[k][j])

ans = -1

for i in range(N):
    for j in range(N):
        k = l[i][j]
        if k != inf:
            ans = max(ans, k)
print(l)
print(ans)

Submission status: Wrong Answer

Solution code:
def get_neighbors(pos):
    i, j = pos
    nbrs = []
    for ii in [i - 1, i + 1]:
        if (ii in path_dic) and (j in path_dic[ii]):
            nbrs.append((ii, j))
    for jj in [j - 1, j + 1]:
        if (i in path_dic) and (jj in path_dic[i]):
            nbrs.append((i, jj))
    return nbrs

def get_furthest_poss(pos):
    i, j = pos
    decided = set([(i, j)])
    furthest = set([(i, j)])
    dist = 0
    for d in range(n * m):
        next_furthest = set()
        for pos in furthest:
            for nbr in get_neighbors(pos):
                if nbr not in decided:
                    decided.add(nbr)
                    next_furthest.add(nbr)
        if len(next_furthest) > 0:
            dist = d + 1
            furthest = next_furthest
        else:
            break
    return dist, furthest

def get_longest_dist():
    for i, js in path_dic.items():
        if len(js) > 0:
            init_pos = (i, js[0])
            break
    d1, poss1 = get_furthest_poss(init_pos)
    d2, poss2 = get_furthest_poss(poss1.pop())
    dd = d2 - d1
    while dd > 0:
        d1, poss1 = (d2, poss2)
        d2, poss2 = get_furthest_poss(poss1.pop())
        dd = d2 - d1
    return d2

n, m = list(map(int, input().split()))
path_dic = {i: [j for j, c in enumerate(input()) if c == '.'] for i in range(n)}
print(get_longest_dist())

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
m = [input() for _ in range(H)]
inf = float("inf")

V = H*W
maze = [[inf]*V for _ in range(V)]

for py in range(H):
    for px in range(W):
        if m[py][px] == "#":
            continue
        candidate = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in candidate:
            if not (0<=x<W and 0<=y<H):continue
            if m[y][x] == "#":
                continue
            maze[W*py+px][W*y+x] = 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

print(max([j for i in maze for j in i if j!=inf]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
m = [input() for _ in range(H)]
inf = float("inf")

V = H*W
maze = [[inf]*V for _ in range(V)]

for py in range(H):
    for px in range(W):
        candidate = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in candidate:
            if not (0<=x<W and 0<=y<H):continue
            if m[py][px] == "#" or m[y][x] == "#":
                continue
            maze[W*py+px][W*y+x] = 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

print(max([j for i in maze for j in i if j!=inf]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
m = [input() for _ in range(H)]
inf = float("inf")

V = H*W
maze = [[inf]*V for _ in range(V)]

for py in range(H):
    for px in range(W):
        candidate = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in candidate:
            if not (0<=x<W and 0<=y<H):continue
            if m[py][px] == "#" or m[y][x] == "#":
                maze[W*py+px][W*y+x] = -1
            else:
                maze[W*py+px][W*y+x] = 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            if maze[i][k]!= -1 and maze[k][j]!=-1:
                maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

print(max([j for i in maze for j in i if j!=inf]))

Submission status: Wrong Answer

Solution code:

from collections import deque
def check(x,y):
    if 0<=x and x<h:
        if 0<=y and y<w:
            return True
    return False

count=0
def bfs():
    while (q):
        x,y,count=q.popleft()
        
        if check(x,y)==False or (x,y) in finished or c[x][y]=='#':
            continue

        else:
            q.append([x,y-1,count+1])
            q.append([x,y+1,count+1])
            q.append([x+1,y,count+1])
            q.append([x-1,y,count+1])
            finished.add((x,y))
            bfscount.append(count)

    return max(bfscount)

q = deque()
h,w=map(int,input().split())
finished = set()
c=[]
for i in range(h):
    c.append(list(map(str,input())))
ans=[]
bfscount=[]
for i in range(h):
    for j in range(w):
        if c[i][j]==".":
            q.append([i,j,0])
            ans.append(bfs())
            finished = set()
            bfscount=[]
print(ans)
print(max(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

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

def bfs(sy, sx):
    if s[sy][sx] == '#':
        return -1
    # 未探索ステータス-1で初期化しておく
    dist = [[-1] * w for _ in range(h)]
    dist[sy][sx] = 0
    dq = deque()
    dq.append((sy, sx))
    while dq:
        y, x = dq.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                if s[ny][nx] == '#':
                    continue
                if dist[ny][nx] != -1:
                    continue
                dist[ny][nx] = dist[y][x] + 1
                dq.append((ny, nx))
    return max(max(dist))


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

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


def bfs(sy, sx):
    if s[sy][sx] == '#':
        return -1
    # 未探索ステータス-1で初期化しておく
    dist = [[-1] * w for _ in range(h)]
    dist[sy][sx] = 0
    dq = deque()
    dq.append((sy, sx))
    while dq:
        y, x = dq.popleft()
        for i in range(4):
            ny = y + dx[i]
            nx = x + dy[i]
            if 0 <= ny < h and 0 <= nx < w:
                if s[ny][nx] == '#':
                    continue
                if dist[ny][nx] != -1:
                    continue
                dist[ny][nx] = dist[y][x] + 1
                dq.append((ny, nx))
    return max(max(dist))


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


def BFS(x,y):
    color=[["white" for i in range(w+2)] for j in range(h+2)]
    D=[[-1 for i in range(w+2)] for j in range(h+2)]

    color[x][y]="gray"
    D[x][y],dis=0,0
    queue=deque([[x,y]])

    while len(queue)!=0:
        a,b=queue.popleft()
        for c,d in [[0,1],[0,-1],[1,0],[-1,0]]:
            X,Y=a+c,b+d
            if S[X][Y]=="." and color[X][Y]=="white":
                color[X][Y]="gray"
                D[X][Y]=D[a][b]+1
                dis=max(dis,D[X][Y])
                queue.append([X,Y])
        color[a][b]="black"

    return dis


h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for i in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))

ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        ans=max(ans,BFS(i,j))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


def BFS(x,y):
    color=[["white" for i in range(w+2)] for j in range(h+2)]
    D=[[-1 for i in range(w+2)] for j in range(h+2)]

    color[x][y]="gray"
    D[x][y],dis=0,0
    queue=deque([[x,y]])

    while len(queue)!=0:
        a,b=queue.popleft()
        for c,d in [[0,1],[0,-1],[1,0],[-1,0]]:
            X,Y=a+c,b+d
            if S[X][Y]=="." and color[X][Y]=="white":
                color[X][Y]="gray"
                D[X][Y]=D[a][b]+1
                dis=max(dis,D[X][Y])
                queue.append([X,Y])
        color[x][y]="black"
        
    return dis


h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for i in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))

ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        ans=max(ans,BFS(i,j))

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import sys
from collections import deque
H,W = (int(_) for _ in input().split())  
f_tmp = []
for _ in range(H):
    f_tmp.append(list(input()))
f = copy.deepcopy(f_tmp)
#dにスタート位置を入力する
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
max_root = 0
for s_i in range(H):
    for s_j in range(W):
        for g_i in range(s_i,H):
            for g_j in range(W):
                f = copy.deepcopy(f_tmp)
                if f[s_i][s_j] != '#' or f[g_i][g_j] != '#':
                    q = deque()
                    q.append([s_i,s_j,0])
                    f[g_i][g_j] = 'g'
                    flg = False
                    while len(q)>0:
                        #print(f)
                        #print(q)
                        node = q.popleft()
                        if node is not None:
                            y = node[0]
                            x = node[1]
                            z = node[2]
                            f[y][x] = '#'
                            for dx, dy in d:
                                nx, ny = x + dx, y + dy
                                if not (0 <= nx < W and 0 <= ny < H) or f[ny][nx] == '#':
                                    #print("NG")
                                    continue
                                else:
                                    tmp = [ny,nx,z+1]
                                    if f[ny][nx] != 'y':
                                        q.append(tmp)
                                    if f[ny][nx] == 'g' and flg == False:
                                        flg = True
                                        if max_root < z+1:
                                            max_root = z+1
                                    f[ny][nx] = 'y'
print(max_root)

Submission status: Wrong Answer

Solution code:
import copy
import sys
from collections import deque
H,W = (int(_) for _ in input().split())  
f_tmp = []
for _ in range(H):
    f_tmp.append(list(input()))
f = copy.deepcopy(f_tmp)
#dにスタート位置を入力する
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
max_root = 0
for s_i in range(H):
    for s_j in range(W):
        for g_i in range(s_i,H):
            for g_j in range(W):
                f = copy.deepcopy(f_tmp)
                q = deque()
                q.append([s_i,s_j,0])
                f[g_i][g_j] = 'g'
                flg = False
                while len(q)>0:
                    #print(f)
                    #print(q)
                    node = q.popleft()
                    if node is not None:
                        y = node[0]
                        x = node[1]
                        z = node[2]
                        f[y][x] = '#'
                        for dx, dy in d:
                            nx, ny = x + dx, y + dy
                            if not (0 <= nx < W and 0 <= ny < H) or f[ny][nx] == '#':
                                #print("NG")
                                continue
                            else:
                                tmp = [ny,nx,z+1]
                                if f[ny][nx] != 'y':
                                    q.append(tmp)
                                if f[ny][nx] == 'g' and flg == False:
                                    flg = True
                                    if max_root < z+1:
                                        max_root = z+1
                                f[ny][nx] = 'y'
print(max_root)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np


H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
B=T.copy()
d=0
c=deque()
for i in range(H):
    for j in range(W):

        if T[i][j] ==1:continue
        s=0
        c.append((i,j))

        t=len(c)
        while t>0:
                s+=1
                t=len(c)
                for k in range(t):
                        m,n = c.popleft()
                        T[m][n]=s
                        if m != H-1:
                                if T[m+1][n]==0:c.append((m+1,n))
                        if m != 0:
                                if T[m-1][n]==0:c.append((m-1,n))
                        if n != W-1:
                                if T[m][n+1]==0:c.append((m,n+1))
                        if n != 0:
                                if T[m][n-1]==0:c.append((m,n-1))
                        #c += (chk_route([c.popleft(),c.popleft()]))

        print(T)
        d = max(d,s)
        T=B.copy()

print(d-2)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
B=T.copy()    
d=0
c=deque() 
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue   
        s=0
        c.append((i,j))
        
        t=len(c)//2
        while t>0:
                s+=1
                t=len(c)//2
                for k in range(t):
                        m,n = c.popleft()
                        T[m][n]=s
                        if m != H-1:
                                if T[m+1][n]==0:c.append((m+1,n))
                        if m != 0:
                                if T[m-1][n]==0:c.append((m-1,n)) 
                        if n != W-1:
                                if T[m][n+1]==0:c.append((m,n+1))
                        if n != 0:
                                if T[m][n-1]==0:c.append((m,n-1))
                        #c += (chk_route([c.popleft(),c.popleft()]))
                
        #print(T)
        d = max(d,s)
        T=B.copy()
        
print(d-2)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np


H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):

        if T[i][j] == 1:continue

        c.append((i,j))
        S[i][j]=1

        while True:
                #print(c)
                try:
                    m,n = c.popleft()
                except IndexError:
                    #print("break")
                    break

                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c.append((m+1,n))
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c.append((m-1,n))
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c.append((m,n+1))
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c.append((m,n-1))
                        S[m][n-1] = S[m][n]+1

        print(S)
        d = max(d,np.max(S))
        S = np.zeros_like(T, dtype=int)

print(d-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np


H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):

        if T[i][j] ==1:continue

        c+=[i,j]
        S[i][j]=1
        
        while True:
            
                #print(c)
                try:
                    m = c.popleft()
                    n = c.popleft()
                except IndexError:
                    break
                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c+=[m+1,n]
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c+=[m-1,n]
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c+=[m,n+1]
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c+=[m,n-1]
                        S[m][n-1] = S[m][n]+1

        print(S)
        d = max(d,np.max(S))
        S = np.zeros_like(T, dtype=int)

print(d-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        c+=[i,j]
        S[i][j]=1
        t=len(c)
        while t>0:
                t=len(c)
                #print(c)
                try:
                    m = c.popleft()
                    n = c.popleft()
                except IndexError:
                    break
                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c+=[m+1,n]
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c+=[m-1,n] 
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c+=[m,n+1]
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c+=[m,n-1]
                        S[m][n-1] = S[m][n]+1
                
        print(S)
        d = max(d,np.max(S))
        S = np.zeros_like(T, dtype=int)
        
print(d-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        c=deque()    
        c+=[i,j]
        S[i][j]=1
        t=len(c)
        while t>0:
                t=len(c)
                try:
                    m = c.popleft()
                    n = c.popleft()
                except IndexError:
                    break
                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c+=[m+1,n]
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c+=[m-1,n] 
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c+=[m,n+1]
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c+=[m,n-1]
                        S[m][n-1] = S[m][n]+1
                
        print(S)
        d = max(d,np.max(S))
        S= np.zeros_like(T, dtype=int)
        
print(d-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        c=deque()    
        s=0
        c+=[i,j]
        S[i][j]=1
        t=len(c)
        while t>0:
                s+=1
                t=len(c)
                try:
                    m = c.popleft()
                    n = c.popleft()
                except IndexError:
                    break
                #S[m][n]=s
                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c+=[m+1,n]
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c+=[m-1,n] 
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c+=[m,n+1]
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c+=[m,n-1]
                        S[m][n-1] = S[m][n]+1
                        #c += (chk_route([c.popleft(),c.popleft()]))
                
        print(S)
        d = max(d,np.max(S))
        S= np.zeros_like(T, dtype=int)
        
print(d)

Submission status: Wrong Answer

Solution code:
row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
 
    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1
 
    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
 
    while adj_list:
    # for p in range(len(adj_list)):
      max_depth = 0
      point = adj_list.pop(0)

      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
          if point[-1] > max_depth:
            max_depth = point[-1]

      result.append(max_depth)

print(max(result))

Submission status: Wrong Answer

Solution code:
row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
 
    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1
 
    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
 
    while adj_list:
    # for p in range(len(adj_list)):
      max_depth = 0
      point = adj_list.pop(0)
      print(point)

      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
          if point[-1] > max_depth:
            max_depth = point[-1]

      result.append(max_depth)

print(max(result))

Submission status: Wrong Answer

Solution code:
row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []

def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]

for r in range(row):
  for c in range(col):

    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1

    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]

    while adj_list:
    # for p in range(len(adj_list)):
      point = adj_list.pop(0)
  
      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
      
      if len(adj_list) == 0:
        result.append(point[-1])
  
print(max(result))