-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.cpp
More file actions
65 lines (52 loc) · 1.09 KB
/
Copy path10026.cpp
File metadata and controls
65 lines (52 loc) · 1.09 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int dy[4]={1,-1,0,0};
int dx[4]={0,0,1,-1};
int visited[100][100];
char RGB[100][100];
void dfs(int y, int x,char color){
for(int i = 0 ; i < 4; i++){
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || ny < 0 || nx >= n || ny >= n)
continue;
if(RGB[ny][nx] == color && !visited[ny][nx]){
visited[ny][nx]++;
dfs(ny,nx,color);
}
}
}
int main() {
int ans[2]={0};
cin >> n;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
cin >> RGB[i][j];
//정상인
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
if(!visited[i][j]){
ans[0]++;
visited[i][j]++;
dfs(i,j,RGB[i][j]);
}
memset(visited,0,sizeof(visited));
//색맹
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
if(RGB[i][j] == 'G')
RGB[i][j] = 'R';
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
if(!visited[i][j]){
ans[1]++;
visited[i][j]++;
dfs(i,j,RGB[i][j]);
}
cout << ans[0] << ' ' << ans[1];
return 0;
}