제출 #646828

#제출 시각아이디문제언어결과실행 시간메모리
646828beaconmcTracks in the Snow (BOI13_tracks)Pypy 3
54.06 / 100
2146 ms1015680 KiB
from heapq import *
n,m = map(int, input().split())

grid = [list(input()) for i in range(n)]
visited = [[0 for i in range(m)]for i in range(n)]
depth = [[0 for i in range(m)]for i in range(n)]

ani = []
if grid[0][0]=="F":
    ani = ["F","R"]
else: ani = ["R","F"]


a = []
heappush(a,(0,0,0))

while len(a):
    node = heappop(a)

    depth[node[1]][node[2]] = node[0]

    for (i,j) in [(1,0),(-1,0),(0,-1),(0,1)]:
        x = node[1] + i
        y = node[2] + j

        if 0<=x<n and 0<=y<m and grid[x][y] != ".":
            if grid[x][y] == ani[node[0]%2] and not visited[x][y]:
                visited[x][y] = True
                heappush(a, (node[0], x,y))

            if grid[x][y] != ani[node[0]%2] and not visited[x][y]:
                visited[x][y] = True
                heappush(a, (node[0]+1, x,y))
maxi = -1

for i in depth:
    maxi = max(maxi, max(i))
print(maxi+1)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...