https://www.acmicpc.net/problem/2589
내 오답 포인트 - 굳이 combination 을 썼다. 그래서 시간초과남.
import sys
from collections import deque
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def bfs(a, b):
global result
q = deque()
visit[a][b] = True
q.append((a, b, 0))
while q:
x, y, cnt = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < m and data[nx][ny] == 'L' and not visit[nx][ny]:
result = max(result, cnt + 1)
visit[nx][ny] = True
q.append((nx, ny, cnt + 1))
input = sys.stdin.readline
n, m = map(int, input().split())
data = []
for i in range(n):
data.append(list(input()))
result = -1e9
for i in range(n):
for j in range(m):
if data[i][j] == 'L':
visit = [[False] * m for _ in range(n)]
bfs(i, j)
print(result)
'알고리즘' 카테고리의 다른 글
[Algorithm] 떡볶이 떡 만들기 (0) | 2022.04.16 |
---|---|
[Algorithm] 10026. 적록색약 (0) | 2022.04.13 |
순열 (Permutation) 알고리즘의 모든 것 (0) | 2020.05.14 |
Boj 1358. 하키 (0) | 2020.01.28 |
[개념] 유클리드기하학,택시기하학 / Boj 3053. 택시 기하학 (0) | 2020.01.28 |