1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : seeys
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/d5f45854d45a402b8e64682b2b4d300f
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
+ #define X first
7
+ #define Y second
8
+ char board[101 ][101 ];
9
+ bool vis[101 ][101 ];
10
+ int n;
11
+ int dx[4 ] = { 1 ,0 ,-1 ,0 };
12
+ int dy[4 ] = { 0 ,1 ,0 ,-1 };
6
13
7
- int main (void ){
8
- ios::sync_with_stdio (0 );
9
- cin.tie (0 );
10
-
14
+ void bfs (int i, int j) {
15
+ queue<pair<int , int >> Q;
16
+ Q.push ({ i,j });
17
+ vis[i][j] = 1 ;
18
+ while (!Q.empty ()) {
19
+ auto cur = Q.front (); Q.pop ();
20
+ for (int dir = 0 ; dir < 4 ; dir++) {
21
+ int nx = cur.X + dx[dir];
22
+ int ny = cur.Y + dy[dir];
23
+ if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue ;
24
+ if (vis[nx][ny] == 1 || board[i][j] != board[nx][ny]) continue ;
25
+ vis[nx][ny] = 1 ;
26
+ Q.push ({ nx,ny });
27
+ }
28
+ }
29
+ }
30
+
31
+ int main (void ) {
32
+
33
+ ios::sync_with_stdio (0 );
34
+ cin.tie (0 );
35
+ cin >> n;
36
+ for (int i = 0 ; i < n; i++) {
37
+ for (int j = 0 ; j < n; j++) {
38
+ cin >> board[i][j];
39
+ }
40
+ }
41
+
42
+ int not_g = 0 ; // 적록색약이 아닌사람
43
+ int is_g = 0 ; // 적록색약인 사람
44
+
45
+ // 적록색약이 아닌 사람의 값을 구하기 위한 과정
46
+ for (int i = 0 ; i < n; i++) {
47
+ for (int j = 0 ; j < n; j++) {
48
+ if (!vis[i][j]) {
49
+ not_g++;
50
+ bfs (i, j);
51
+ }
52
+ }
53
+ }
54
+
55
+ memset (vis, 0 , sizeof (vis)); // 적록색약인 사람을 구하기위한 방문배열 초기화
56
+
57
+ // 적록색약은 초록과 빨강을 구분 못하므로 초록이면 빨강으로 바꿔줌
58
+ for (int i = 0 ; i < n; i++) {
59
+ for (int j = 0 ; j < n; j++) {
60
+ if (board[i][j] == ' G' )
61
+ board[i][j] = ' R' ;
62
+ }
63
+ }
64
+
65
+ // 적록색약인 사람의 값을 구하기 위한 과정
66
+ for (int i = 0 ; i < n; i++) {
67
+ for (int j = 0 ; j < n; j++) {
68
+ if (!vis[i][j]) {
69
+ is_g++;
70
+ bfs (i, j);
71
+ }
72
+ }
73
+ }
74
+
75
+ cout << not_g << " " << is_g;
76
+ return 0 ;
11
77
}
0 commit comments