-
Notifications
You must be signed in to change notification settings - Fork 0
/
안전영역.cpp
71 lines (63 loc) · 1.36 KB
/
안전영역.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
#include "pch.h"
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n;
int map[101][101];
int direction[4][2] = { {0, -1}, {0, 1}, {1, 0}, {-1, 0} };
int min_g = 100;
int max_g;
int result = 1;
vector<vector<bool>> visit;
void bfs(int x, int y, int k) { //k´Â ºñ¿Â ¸®ÅÍ
visit[x][y] = true;
queue<pair<int, int>> q;
q.push(make_pair(x, y));
while (!q.empty()) {
pair<int, int> cur = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int n_x = cur.first + direction[i][0];
int n_y = cur.second + direction[i][1];
if (n_x <1 || n_x>n || n_y<1 || n_y>n) continue;
if (map[n_x][n_y]<=k || visit[n_x][n_y]) continue;
visit[n_x][n_y] = true;
q.push(make_pair(n_x, n_y));
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> map[i][j];
if (map[i][j] < min_g) {
min_g = map[i][j];
}
if (map[i][j] > max_g) {
max_g = map[i][j];
}
}
}
for (int k = min_g; k < max_g; k++) {
visit = vector<vector<bool>>(n + 1, vector<bool>(n + 1));
int count = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (!visit[i][j] && map[i][j] > k) {
bfs(i, j, k);
count++;
}
}
}
if (count > result) {
result = count;
}
}
cout << result;
return 0;
}