-
Notifications
You must be signed in to change notification settings - Fork 0
/
10026.cpp
88 lines (77 loc) · 1.9 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N = 0, cnt = 1, blind_cnt = 1;
char C = ' ';
int x = 0, y = 0;
int BFS(vector<vector<int>> &visit, vector<vector<char>> v, int x, int y, int cnt)
{
int move_x[4] = {1, 0, -1, 0};
int move_y[4] = {0, 1, 0, -1};
visit[y][x] = 1; //(x,y) ¹æ¹®
for (int i = 0; i < 4; i++) // 4¹æÇâ Ž»ö
{
int ax = x + move_x[i], ay = y + move_y[i];
if (ax >= 0 && ay >= 0 && ax < N && ay < N)
{
if (v[ay][ax] == C && visit[ay][ax] == 0)
{
BFS(visit, v, ax, ay, cnt);
}
}
else
continue;
}
return cnt;
}
int main()
{
cin >> N;
if (N == 0)
cout << "0 0";
vector<vector<char>> v(N, vector<char>(N, 0));
vector<vector<char>> blind_v(N, vector<char>(N, 0));
vector<vector<int>> visit(N, vector<int>(N, 0));
vector<vector<int>> blind_visit(N, vector<int>(N, 0));
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cin >> v[i][j];
if (v[i][j] == 'G')
blind_v[i][j] = 'R';
else
blind_v[i][j] = v[i][j];
}
}
C = v[0][0];
BFS(visit, v, 0, 0, cnt);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (visit[i][j] == 0)
{
++cnt;
C = v[i][j];
BFS(visit, v, j, i, cnt);
}
}
}
C = blind_v[0][0];
BFS(blind_visit, blind_v, 0, 0, blind_cnt);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (blind_visit[i][j] == 0)
{
++blind_cnt;
C = blind_v[i][j];
BFS(blind_visit, blind_v, j, i, blind_cnt);
}
}
}
cout << cnt << " " << blind_cnt;
}