-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2468.cpp
More file actions
62 lines (62 loc) · 1.54 KB
/
Copy path2468.cpp
File metadata and controls
62 lines (62 loc) · 1.54 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
#include <iostream>
#include <algorithm>
#include <string.h>
#define MAX 100
using namespace std;
void dfs(bool graph[][MAX], int x, int y,int x_end ,int y_end){
int x_pos[4] = {-1,0,1,0}, y_pos[4] = {0,1,0,-1};
graph[x][y] = false;
int new_x, new_y;
for(int i = 0; i<4;i++){
new_x = x + x_pos[i];
new_y = y + y_pos[i];
if(new_x>= 0 && new_x <x_end){
if(new_y>= 0 && new_y <y_end){
if(graph[new_x][new_y] == true){
dfs(graph ,new_x,new_y, x_end, y_end);
}
}
}
}
}
int main(){
int N, BIG =0;
int map[MAX][MAX];
bool graph[MAX][MAX];
cin >> N;
for(int i =0; i< N;i++){
for(int j=0; j< N; j++){
cin >> map[i][j];
if(BIG < map[i][j]){
BIG = map[i][j];
}
}
}
int counting, answer;
for(int i=1;i<=BIG;i++){
for(int j =0;j < N;j++){
memset(graph[j], false, sizeof(bool)* N);
}
for(int x = 0; x< N; x++){
for(int y = 0; y< N; y++){
if(map[x][y] >= i){
graph[x][y] = true;
}
}
}
counting = 0;
for(int x = 0; x< N; x++){
for(int y = 0; y< N; y++){
if(graph[x][y]== true){
dfs(graph,x,y,N,N);
counting++;
}
}
}
if(counting > answer){
answer = counting;
}
}
cout << answer;
return 0;
}