-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-B 2589.py
More file actions
44 lines (35 loc) · 1.02 KB
/
3-B 2589.py
File metadata and controls
44 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from collections import deque
n, m = map(int, input().split())
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]
board = [[' '] * m for _ in range(n)]
q = deque()
posL = deque()
def bfs(y, x):
visited = [[0] * m for _ in range(n)]
visited[y][x] = 1
q.append((y, x))
ret = 0
while q:
qy, qx = q.popleft()
for i in range(4):
ny = dy[i] + qy
nx = dx[i] + qx
if ny < 0 or ny >= n or nx < 0 or nx >= m or visited[ny][nx] or board[ny][nx] == "W":
continue
if board[ny][nx] == "L" and visited[ny][nx] == 0:
visited[ny][nx] = visited[qy][qx] + 1
q.append((ny, nx))
ret = max(ret,visited[ny][nx])
return ret-1
for i in range(n):
data = input()
for j in range(m):
board[i][j] = data[j]
if board[i][j] == "L":
posL.append((i, j))
ret2 = float('-inf')
for posY,posX in posL :
visited = [[0] * m for _ in range(n)]
ret2 = max(ret2, bfs(posY,posX))
print(ret2)