-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBACKJOON10026.py
More file actions
54 lines (45 loc) · 1.69 KB
/
BACKJOON10026.py
File metadata and controls
54 lines (45 loc) · 1.69 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
#적록색약
import sys
from collections import deque
input = sys.stdin.readline
def getSection(graph):
size = len(graph)
result = 0
for i in range(size):
for j in range(size):
if graph[i][j] != -1:
queue = deque()
queue.append((i, j, graph[i][j]))
graph[i][j] = -1
while queue:
x, y, cur = queue.popleft()
if y > 0 and graph[x][y - 1] != -1 and graph[x][y - 1] == cur:
queue.append((x, y - 1, graph[x][y - 1]))
graph[x][y - 1] = -1
if x < size - 1 and graph[x + 1][y] != -1 and graph[x + 1][y] == cur:
queue.append((x + 1, y, graph[x + 1][y]))
graph[x + 1][y] = -1
if y < size - 1 and graph[x][y + 1] != -1 and graph[x][y + 1] == cur:
queue.append((x, y + 1, graph[x][y + 1]))
graph[x][y + 1] = -1
if x > 0 and graph[x - 1][y] != -1 and graph[x - 1][y] == cur:
queue.append((x - 1, y, graph[x - 1][y]))
graph[x - 1][y] = -1
result += 1
return result
n = int(input())
normal = [ [0]*n for _ in range(n) ]
diff = [ [0]*n for _ in range(n) ]
for i in range(n):
color = input().strip()
for j in range(n):
if color[j] == "R":
normal[i][j] = 1
diff[i][j] = 1
elif color[j] == "G":
normal[i][j] = 2
diff[i][j] = 1
elif color[j] == "B":
normal[i][j] = 3
diff[i][j] = 3
print(f"{getSection(normal)} {getSection(diff)}")