Skip to content

Commit 63258e3

Browse files
committed
96차 1번 문제 풀이 (푸는중)
1 parent 92cb7f1 commit 63258e3

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

live9/test96/문제1/박희경.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from collections import *
2+
3+
def solution(board):
4+
answer = 0
5+
6+
dx = [-1, 1, 0, 0]
7+
dy = [0, 0, -1, 1]
8+
9+
n = len(board)
10+
m = len(board[0])
11+
12+
def bfs(x, y):
13+
q = deque([(x, y)])
14+
cnt = 0
15+
while q:
16+
x, y = q.popleft()
17+
cnt += 1
18+
for i in range(4):
19+
nx = x + dx[i]
20+
ny = y + dy[i]
21+
if 0 <= nx < n or 0 <= y < m or board[x][y] == 'D':
22+
if board[nx][ny] == 'G':
23+
return cnt
24+
q.append((nx, ny))
25+
26+
for i in range(n):
27+
for j in range(m):
28+
if board[i][j] == 'R':
29+
cnt += bfs(i, j)
30+
print(cnt)
31+
32+
return answer

0 commit comments

Comments
 (0)