-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.cpp
More file actions
61 lines (54 loc) · 1.31 KB
/
10026.cpp
File metadata and controls
61 lines (54 loc) · 1.31 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
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int dy[4] = {1,-1,0,0};
int dx[4] = {0,0,1,-1};
char arr[111][111];
int n;
int result1, result2;
int visited[111][111];
void dfs(int y, int x, int flag){
visited[y][x]=1;
for(int d=0; d<4; d++){
if(visited[y+dy[d]][x+dx[d]]) continue;
if(!flag){
if(arr[y][x] == arr[y+dy[d]][x+dx[d]]){
dfs(y+dy[d], x+dx[d], 0);
}
}
else{
if(arr[y][x] == arr[y+dy[d]][x+dx[d]]){
dfs(y+dy[d], x+dx[d], 1);
}
else if( (arr[y][x]=='R' && arr[y+dy[d]][x+dx[d]]=='G') || (arr[y][x]=='G' && arr[y+dy[d]][x+dx[d]]=='R')){
dfs(y+dy[d], x+dx[d], 1);
}
}
}
}
int main(){
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(visited[i][j]) continue;
dfs(i, j, 0);
result1++;
}
}
memset(visited, 0, sizeof(visited));
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(visited[i][j]) continue;
dfs(i, j, 1);
result2++;
}
}
cout<<result1<<" "<<result2<<endl;
return 0;
}