-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.cpp
More file actions
147 lines (103 loc) · 2.26 KB
/
10026.cpp
File metadata and controls
147 lines (103 loc) · 2.26 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
using namespace std;
int n;
char map[102][102];
int vis[102][102];
int cnt;
vector<int>v_j;//적록색약이 아닌사람
vector<int>v_g;//적록색약인 사람
queue<pair<int, int>>q;
int dx[] = { 0,1,-1,0 };
int dy[] = { -1,0,0,1 };
void bfs_j(int a, int b,char color) {
q.push({ a,b });
vis[q.front().first][q.front().second] = 1;//방문 여부 확인
while (!q.empty())
{
cnt++;
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int i = 0;i < 4;i++) {
int movex = x + dx[i];
int movey =y + dy[i];
if (movex >= 0 && movex < n&&movey >= 0 && movey < n) {
if (map[movex][movey] == color&&vis[movex][movey] == 0) {
q.push({ movex,movey });
vis[movex][movey] = 1;
}
}
}
}
}
void bfs_g(int a, int b, char color) {
q.push({ a,b });
vis[q.front().first][q.front().second] = 1;//방문 여부 확인
while (!q.empty())
{
cnt++;
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int i = 0;i < 4;i++) {
int movex = x + dx[i];
int movey = y + dy[i];
if (movex >= 0 && movex < n&&movey >= 0 && movey < n) {
if (color == 'R' || color == 'G') {
if ((map[movex][movey] == 'R' || map[movex][movey] == 'G') && vis[movex][movey] == 0) {
q.push({ movex,movey });
vis[movex][movey] = 1;
}
}
else if (color == 'B') {
if (map[movex][movey] == color&& vis[movex][movey] == 0) {
q.push({ movex,movey });
vis[movex][movey] = 1;
}
}
}
}
}
}
int main() {
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 0;i < n;i++) {//문자열 배열에 저장
string str;
cin >> str;
for (int j = 0;j < str.size();j++)
{
map[i][j] = str[j];
}
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < n;j++) {
if (vis[i][j] == 0) {
bfs_j(i, j, map[i][j]);
v_j.push_back(cnt);
cnt = 0;
}
}
}
memset(vis, 0, sizeof(vis));
for (int i = 0;i < n;i++) {
for (int j = 0;j < n;j++) {
if (vis[i][j] == 0) {
bfs_g(i, j, map[i][j]);
v_g.push_back(cnt);
cnt = 0;
}
}
}
cout << v_j.size() << " ";
cout << v_g.size() << "\n";
return 0;
}