https://www.acmicpc.net/problem/15559
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 | n, m = map(int, input().split()) MAP = [list(input()) for _ in range(n)] check = [[0]*m for _ in range(n)] dic = {'N':(-1,0), 'S':(1,0), 'E':(0,1), 'W':(0,-1)} def dfs(y,x,cnt): global n, m if check[y][x]: return check[y][x] check[y][x] = cnt ny = y + dic[MAP[y][x]][0] nx = x + dic[MAP[y][x]][1] check[y][x] = dfs(ny, nx, cnt) return check[y][x] result = 0 for i in range(n): for j in range(m): if not check[i][j]: a = dfs(i,j,result+1) result = max(a, result) print(result) | cs |
728x90
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[Python]2529. 부등호 (0) | 2019.04.16 |
---|---|
[Python]17127. 벚꽃이 정보섬에 피어난 이유 (0) | 2019.04.14 |
[Python]13335. 트럭 (0) | 2019.04.13 |
[Python]16985. Maaaaaaaaaaze (0) | 2019.04.12 |
[Python]17070. 파이프 옮기기1 (0) | 2019.04.12 |
댓글