-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapSoc.cpp
More file actions
81 lines (67 loc) · 1.8 KB
/
capSoc.cpp
File metadata and controls
81 lines (67 loc) · 1.8 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
#include <iostream>
using namespace std;
int N = 502;
int visited[N][N];
queue<pair<int, pair<int, int>>> que
int main () {
int t;
cin >> t;
while (t--) {
int currM = -90;
int n, m;
cin >> n >> m;
int a[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
visited[i][j] = 0;
currM = max(a[i][j], currM);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == currM) {
visited[i][j] = 1;
que.push(((i, j), 0));
}
}
}
int sol = 0;
int i = 0;
int j = 0;
int dist = 0;
while (!que.empty()) {
i = que.front().second.first;
j = que.front().second.second;
visited[i][j] = 1;
dist = que.front().first;
que.pop();
sol = max(sol, dist);
if (i+1 < n && j+1 < m) {
que.push(((i+1, j+1), dist+1))
}
if (i+1 < n && j-1 >= 0) {
que.push(((i+1, j-1), dist+1))
}
if (i-1 >= 0 && j+1 < m) {
que.push(((i-1, j+1), dist+1))
}
if (i-1 >= 0 && j-1 >= 0) {
que.push(((i-1, j-1), dist+1))
}
if (i+1 < n) {
que.push(((i+1, j), dist+1))
}
if (j+1 < m) {
que.push(((i, j+1), dist+1))
}
if (i-1 >= 0) {
que.push(((i-1, j), dist+1))
}
if (j-1 >= 0) {
que.push(((i, j-1), dist+1))
}
}
cout << sol << "\n";
}
}