-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10026.cpp
70 lines (63 loc) · 1.19 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
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
string map[101];
bool visited[101][101];
int N;
int cnt;
int mx[4] = {0,0,-1,1};
int my[4] = {1,-1,0,0};
void dfs(int x,int y,char sig) {
visited[x][y] = true;
cnt++;
for (int i = 0; i < 4; i++) {
int nx = x + mx[i];
int ny = y + my[i];
if (0 <= nx && 0 <= ny && nx < N && ny < N) {
if (!visited[nx][ny] && map[nx][ny] == sig)
dfs(nx, ny, sig);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int x = 0; x < N; x++) {
cin >> map[x];
}
vector<int> v1;
for (int x = 0; x < N; x++) {
for (int y = 0; y < N; y++) {
if (!visited[x][y]) {
cnt = 0;
dfs(x, y, map[x][y]);
v1.push_back(cnt);
}
}
}
cout << v1.size() << " ";
for (int x = 0; x < N; x++) {
for (int y = 0; y < N; y++) {
if (map[x][y] == 'G') map[x][y] = 'R';
}
}
v1.clear();
memset(visited, 0, sizeof(visited));
for (int x = 0; x < N; x++) {
for (int y = 0; y < N; y++) {
if (!visited[x][y]) {
cnt = 0;
dfs(x, y, map[x][y]);
v1.push_back(cnt);
}
}
}
cout << v1.size() << " ";
return 0;
}