-
Notifications
You must be signed in to change notification settings - Fork 1
/
10026.cpp
78 lines (69 loc) · 1.56 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
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
void process(vector<vector<char> > &a, int n, pair<int, int> c) {
queue<pair<int, int> > q;
q.push(c);
char color = a[c.first][c.second];
a[c.first][c.second] = 'X';
while (!q.empty()) {
pair<int, int> cur = q.front();
q.pop();
int x = cur.first;
int y = cur.second;
if (x > 0 && a[x-1][y] == color) {
a[x-1][y] = 'X';
q.push(make_pair(x-1, y));
}
if (x < n-1 && a[x+1][y] == color) {
a[x+1][y] = 'X';
q.push(make_pair(x+1, y));
}
if (y > 0 && a[x][y-1] == color) {
a[x][y-1] = 'X';
q.push(make_pair(x, y-1));
}
if (y < n-1 && a[x][y+1] == color) {
a[x][y+1] = 'X';
q.push(make_pair(x, y+1));
}
}
}
void solve(void) {
int n, ans = 0;
cin >> n;
vector<vector<char> > a(n, vector<char>(n)), b(n, vector<char>(n));
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
cin >> a[i][j];
b[i][j] = a[i][j] == 'R' ? 'G' : a[i][j];
}
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (a[i][j] == 'R' || a[i][j] == 'G' || a[i][j] == 'B') {
ans++;
process(a, n, make_pair(i, j));
}
}
}
cout << ans << " ";
ans = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (b[i][j] == 'G' || b[i][j] == 'B') {
ans++;
process(b, n, make_pair(i, j));
}
}
}
cout << ans;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
}