-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10026_적록색약.py
More file actions
78 lines (52 loc) · 1.46 KB
/
10026_적록색약.py
File metadata and controls
78 lines (52 loc) · 1.46 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#2023-05-18-Week6-과제
#10026_적록색약
'''
입력 :
1. 입력 크기 1 ≤ N ≤ 100
2. 그리드 입력 (N*N)
출력 :
적록색약 아닌 사람의 구역, 적록색약인 사람의 구역
'''
#런타임 에러 발생
from collections import deque
import sys
import string
sys.setrecursionlimit(100000) #재귀
input=sys.stdin.readline()
N = int(input())
matrix = [list(input().rstrip()) for i in range(N)]
visited = [[0]*N for i in range(N)] #방문 안 한 상태로 설정
def dfs(x,y) :
move_x = [-1,1,0,0]
move_y = [0,0,-1,1]
color = matrix[x][y] #R, G, B
visited[x][y] = True #방문
for i in range(4) : #상하좌우
new_x = x + move_x[i]
new_y = y + move_y[i]
if {(0 <= new_x <= N - 1)
and (0 <= new_y <= N - 1)
and (visited[new_x][new_y] == False)}:
if color == matrix[new_x][new_y] :
dfs(new_x,new_y)
#정상
normal = 0
for x in range(N) :
for y in range(N) :
if visited[x][y] == False :
dfs(x,y)
normal += 1
#적록색약
noRG = 0
for x in range(N) : #적록색약 기준으로 색 변경
for y in range(N) :
if matrix[x][y] == 'R' or matrix[x][y] == 'G' :
matrix[x][y] == 'g'
visited = [[0]*N for i in range(N)] #방문횟수 초기화
for x in range(N) :
for y in range(N) :
if visited[x][y] == False :
dfs(x,y)
noRG += 1
#출력
print(normal, noRG)