-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10026.cpp
91 lines (69 loc) · 1.73 KB
/
10026.cpp
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
//
// Created by 융미 on 2019-04-20.
//10026 적록색약
#include <iostream>
#include <cstring>
#include <string>
#include <utility>
#include <queue>
using namespace std;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,-1,1};
int n;
string arr[100];
bool vis[100][100];
void getInput();
int bfs(bool b); //적록 색약이 아닌 사람 false
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
getInput();
cout << bfs(false) << ' ';
memset(vis,false,sizeof(vis));
cout << bfs(true);
return 0;
}
void getInput()
{
cin >> n;
string s;
for(int i = 0; i<n; i++)
{
cin >> s;
arr[i] = s;
}
}
int bfs(bool b)
{
int num = 0;
char target = '\0';
for(int i = 0; i<n; i++)
{
for(int j = 0; j<n; j++){
if(vis[i][j] == 1) continue;
target = arr[i][j];
queue<pair<int,int>> q;
q.push({i,j});
vis[i][j] = 1;
while(!q.empty()){
auto cur = q.front();
q.pop();
for(int k = 0; k<4; k++)
{
int nx = cur.first+dx[k];
int ny = cur.second + dy[k];
if(nx < 0 || nx >= n || ny<0 || ny >= n) continue;
if(vis[nx][ny] == 1) continue;
//적록 색약 일 경우
if(b && (target == 'R' || target == 'G') && arr[nx][ny] == 'B') continue;
if(b && (target == 'B') && (arr[nx][ny] != target)) continue;
if(!b && (arr[nx][ny] != target)) continue;
vis[nx][ny] = 1;
q.push({nx,ny});
}
}
num++;
}
}
return num;
}