-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.py
More file actions
40 lines (35 loc) · 1011 Bytes
/
10026.py
File metadata and controls
40 lines (35 loc) · 1011 Bytes
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
import sys
sys.setrecursionlimit(50000)
def dfs(x, y, color, mapping):
dx = [-1,0,1,0]
dy = [0,-1,0,1]
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<=nx<n and 0<=ny<n and not isvisited[nx][ny] and mapping[nx][ny] == color:
isvisited[nx][ny] = 1
dfs(nx, ny, color, mapping)
n = int(input())
maps = []
for i in range(n):
maps.append(sys.stdin.readline().rstrip())
colorBlindmaps=[]
for ma in maps:
colorBlindmaps.append(ma.replace("R","G"))
normal = 0
isvisited = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
color = maps[i][j]
if not isvisited[i][j]:
dfs(i, j, color, maps)
normal += 1
colorBlind = 0
isvisited = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
color = colorBlindmaps[i][j]
if not isvisited[i][j]:
dfs(i, j, color, colorBlindmaps)
colorBlind+= 1
print(str(normal) + " " + str(colorBlind))