-
Notifications
You must be signed in to change notification settings - Fork 0
/
12946.cpp
67 lines (62 loc) · 1.47 KB
/
12946.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
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX = 51;
int n;
int ans = 0;
char arr[MAX][MAX];
bool check[MAX][MAX];
int dx[] = {-1, -1, 0, 1, 1, 0};
int dy[] = {0, 1, 1, 0, -1, -1};
void bfs(int _i, int _j) {
queue<pii> q;
q.push({_i, _j});
check[_i][_j] = true;
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
int cnt = 0;
int flag = 0;
for (int i = 0; i < 7; i++) {
int nx = x + dx[i % 6];
int ny = y + dy[i % 6];
if (nx < 0 || nx >= n || ny < 0 || ny >= n || arr[nx][ny] == '-') {
flag = 0;
continue;
}
if (i != 6) {
cnt++;
}
flag++;
if (cnt > 0) {
ans = max(ans, 2);
}
if (flag >= 2) {
ans = max(ans, 3);
}
if (!check[nx][ny]) {
check[nx][ny] = true;
q.push({nx, ny});
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
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 (!check[i][j] && arr[i][j] == 'X') {
ans = max(ans, 1);
bfs(i, j);
}
}
}
cout << ans << "\n";
}