-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path백준-안전영역.cpp.txt
102 lines (93 loc) · 1.55 KB
/
백준-안전영역.cpp.txt
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
99
100
101
// ConsoleApplication5.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//
#include<iostream>
#include <queue>
#include <cstdio>
#include<algorithm>
using namespace std;
int N;
int arr[101][101];
int save[101][101];
bool visit[101][101];
int Max_Height = 0;
int safe_space = 0;
int Max_safe = 0;
void rain(int height)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (arr[i][j] <= height)
save[i][j] = 1; //잠긴다
else
save[i][j] = 0;//안잠긴다
}
}
}
void dfs(int x, int y)
{
visit[x][y] = true;
if (x + 1 < N&&visit[x + 1][y] == false && save[x + 1][y] == 0)
{
dfs(x + 1, y);
}
if (y + 1 < N&&visit[x][y+1] == false && save[x][y+1] == 0)
{
dfs(x, y+1);
}
if (x - 1 >=0&&visit[x - 1][y] == false && save[x - 1][y] == 0)
{
dfs(x - 1, y);
}
if (y - 1 >= 0&&visit[x][y-1] == false && save[x][y-1] == 0)
{
dfs(x, y-1);
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cin >> arr[i][j];
visit[i][j] = false;
if (arr[i][j] > Max_Height)
{
Max_Height = arr[i][j];
}
}
}
for (int i = 0; i < Max_Height; i++)
{
rain(i);
safe_space = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
visit[i][j] = false;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (visit[i][j] == false && save[i][j] == 0)
{
dfs(i, j);
safe_space++;
}
}
}
if (Max_safe < safe_space)
{
Max_safe = safe_space;
}
}
cout << Max_safe<<endl;
return 0;
}