-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.cpp
More file actions
98 lines (90 loc) · 1.59 KB
/
10026.cpp
File metadata and controls
98 lines (90 loc) · 1.59 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
char arr[101][101];
int ck[101][101];
int n;
int alcnt;
int dfs(int i, int j)
{
ck[i][j] = 1;
if(i+1<n)
{
if(arr[i][j]==arr[i+1][j]&&ck[i+1][j] == 0)
{
dfs(i+1,j);
}
}
if(j+1<n)
{
if(arr[i][j]==arr[i][j+1]&&ck[i][j+1] == 0)
{
dfs(i,j+1);
}
}
if(i-1>=0)
{
if(arr[i][j]==arr[i-1][j]&&ck[i-1][j] == 0)
{
dfs(i-1,j);
}
}
if(j-1>=0)
{
if(arr[i][j]==arr[i][j-1]&&ck[i][j-1] == 0)
{
dfs(i,j-1);
}
}
return 0;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int fst;
cin>>n;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
cin>>arr[i][j];
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(ck[i][j]==0)
{
dfs(i,j);
alcnt++;
}
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(arr[i][j]=='R') arr[i][j]='G';
ck[i][j] = 0;
}
}
fst = alcnt;
alcnt = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(ck[i][j]==0)
{
dfs(i,j);
alcnt++;
}
}
}
cout<<fst<<" "<<alcnt<<"\n";
}