File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ #2023-05-18-Week6-과제
2+ #10026_적록색약
3+
4+ '''
5+ 입력 :
6+ 1. 입력 크기 1 ≤ N ≤ 100
7+ 2. 그리드 입력 (N*N)
8+
9+ 출력 :
10+ 적록색약 아닌 사람의 구역, 적록색약인 사람의 구역
11+ '''
12+
13+
14+
15+
16+ #런타임 에러 발생
17+
18+ from collections import deque
19+ import sys
20+ import string
21+
22+ sys .setrecursionlimit (100000 ) #재귀
23+ input = sys .stdin .readline ()
24+
25+ N = int (input ())
26+ matrix = [list (input ().rstrip ()) for i in range (N )]
27+
28+ visited = [[0 ]* N for i in range (N )] #방문 안 한 상태로 설정
29+
30+
31+ def dfs (x ,y ) :
32+
33+ move_x = [- 1 ,1 ,0 ,0 ]
34+ move_y = [0 ,0 ,- 1 ,1 ]
35+
36+ color = matrix [x ][y ] #R, G, B
37+ visited [x ][y ] = True #방문
38+
39+ for i in range (4 ) : #상하좌우
40+ new_x = x + move_x [i ]
41+ new_y = y + move_y [i ]
42+ if {(0 <= new_x <= N - 1 )
43+ and (0 <= new_y <= N - 1 )
44+ and (visited [new_x ][new_y ] == False )}:
45+ if color == matrix [new_x ][new_y ] :
46+ dfs (new_x ,new_y )
47+
48+ #정상
49+ normal = 0
50+
51+ for x in range (N ) :
52+ for y in range (N ) :
53+ if visited [x ][y ] == False :
54+ dfs (x ,y )
55+ normal += 1
56+
57+ #적록색약
58+ noRG = 0
59+ for x in range (N ) : #적록색약 기준으로 색 변경
60+ for y in range (N ) :
61+ if matrix [x ][y ] == 'R' or matrix [x ][y ] == 'G' :
62+ matrix [x ][y ] == 'g'
63+
64+ visited = [[0 ]* N for i in range (N )] #방문횟수 초기화
65+ for x in range (N ) :
66+ for y in range (N ) :
67+ if visited [x ][y ] == False :
68+ dfs (x ,y )
69+ noRG += 1
70+
71+ #출력
72+ print (normal , noRG )
73+
74+
75+
76+
77+
78+
You can’t perform that action at this time.
0 commit comments