Submission #9513468


Source Code Expand

import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF = 10 ** 3
(H, W) = list(map(int,input().split()))
# print(H,W)

S = []
N = H * W
c = [[INF for j in range(N)] for u in range(N)]
d = [[INF for j in range(H*W)] for u in range(H*W)]

for k in range(N):
    c[k][k] = 0
    d[k][k] = 0

for i in range(H):
    S.append(input())

#print(S)

def vindex(i,j):
    global W
    return W * (i-1) + j -1

# print(vindex(H,W))
for i in range(1,H+1):
    for j in range(1,W+1):
        index = vindex(i,j)
        s = S[i-1][j-1]
        # print(index,s)
        if i != 1:
            index_t = vindex(i-1,j)
            sup = S[i-2][j-1]
            if ( s == "." and sup == "."):
                d[index][index_t]=1 
                d[index_t][index]=1
                
        if i != H:
            index_t = vindex(i+1,j)
            sup = S[i][j-1]
            if ( s == "." and sup == "."):
                d[index][index_t]=1 
                d[index_t][index]=1
        if j != 1:
            index_t = vindex(i,j-1)
            sup = S[i-1][j-2]
            if ( s == "." and sup == "."):
                d[index][index_t]=1 
                d[index_t][index]=1
        if j != W:
            index_t = vindex(i,j+1)
            sup = S[i-1][j]
            if ( s == "." and sup == "."):
                d[index][index_t]=1 
                d[index_t][index]=1

#print("D",d)


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

ans = 0 
for i in range(N):
    for j in range(N):

        if (d[i][j] != INF and d[i][j] > ans):
            ans = d[i][j]

print(ans)

Submission Info

Submission Time
Task D - Maze Master
User MyOden
Language PyPy3 (2.4.0)
Score 400
Code Size 1752 Byte
Status AC
Exec Time 1191 ms
Memory 45980 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 16
Set Name Test Cases
Sample sample_01, sample_02
All hand_01, hand_02, hand_03, hand_04, hand_05, hand_06, hand_07, hand_08, hand_09, hand_10, sample_01, sample_02, small_01, small_02, small_03, small_04
Case Name Status Exec Time Memory
hand_01 AC 1106 ms 44636 KiB
hand_02 AC 1105 ms 44636 KiB
hand_03 AC 1191 ms 44380 KiB
hand_04 AC 1104 ms 44636 KiB
hand_05 AC 1103 ms 45916 KiB
hand_06 AC 1113 ms 44636 KiB
hand_07 AC 1102 ms 44636 KiB
hand_08 AC 1097 ms 44380 KiB
hand_09 AC 262 ms 41692 KiB
hand_10 AC 302 ms 41564 KiB
sample_01 AC 164 ms 38256 KiB
sample_02 AC 173 ms 38768 KiB
small_01 AC 163 ms 38256 KiB
small_02 AC 176 ms 39536 KiB
small_03 AC 978 ms 45980 KiB
small_04 AC 177 ms 39536 KiB