Skip to content

Commit

Permalink
Merge pull request #195 from AlgoLeadMe/17-H0ngJu
Browse files Browse the repository at this point in the history
17-H0ngJu
  • Loading branch information
H0ngJu authored May 26, 2024
2 parents b859ae1 + dd3422e commit 3fa8bfb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions H0ngJu/BFS/적록색약.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
sys.setrecursionlimit(10**6)
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N = int(input())
arr = [[i for i in input()]for _ in range(N)]
visited = [[0] * N for _ in range(N)]
direc = [(1,0), (-1,0), (0,1), (0,-1)]
result = [0, 0]

def bfs(x, y, color):
q = deque([(x,y)])
visited[x][y] = 1
while q:
cx, cy = q.popleft()
for dx, dy in direc:
nx = dx + cx
ny = dy + cy
if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color:
q.append((nx, ny))
visited[nx][ny] = 1


for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[0] += 1

visited = [[0] * N for _ in range(N)]

for i in range(N):
for j in range(N):
if arr[i][j] == "R":
arr[i][j] = "G"

for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[1] += 1


print(result[0], result[1], end=" ")
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
| 14차시 | 2024.05.09 | DFS | [치킨배달](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 |
| 15차시 | 2024.05.14 | 그리디 | [A와 B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 16차시 | 2024.05.14 | BFS | [뱀과 사다리 게임](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 |
| 17차시 | 2024.05.22 | BFS | [적록색약](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 |

---

0 comments on commit 3fa8bfb

Please sign in to comment.