-
Notifications
You must be signed in to change notification settings - Fork 0
/
P8325_2.cpp
102 lines (96 loc) · 2.6 KB
/
P8325_2.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
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
#include <iostream>
int n, m;
bool map[2010][2010] = {0};
int sum[2010][2010] = {0};
bool shouldHereBeTrue(int x, int y, int size) {
if (x == 0 || x == size - 1) {
if (y == size / 2) {
return true;
}
}
x += 1; y += 1;
int mid = size / 2 +1;
if (y <= mid) {
return (x == mid + y || x == mid - y);
} else {
int off = size - y;
return (x == mid - off || x == mid + off);
}
}
bool check2(int topX, int topY) {
// 1. find bottom
int bottomY = -1;
for (int i = topY+1; i <= m; i++) {
if (map[topX][i]) {
bottomY = i;
break;
}
}
if (bottomY == -1)
return false;
int height = bottomY - topY + 1;
if (height % 2 == 0) return false;
int startX = topX; int startY = topY - height / 2;
for (int i = 0; i < height; i++) {
for (int j = 0; j < height; j++) {
if (!shouldHereBeTrue(i, j, height)) return false;
}
}
return true;
}
bool check(int topX, int topY) {
// 1. find bottom
int bottomY = -1;
for (int i = topY+1; i <= m; i++) {
if (map[topX][i]) {
bottomY = i;
break;
}
}
if (bottomY == -1)
return false;
int height = bottomY - topY + 1;
if (height % 2 == 0) return false;
height -= 2;
// 2. check border
for (int i = 1; i <= height / 2 + 1; i++) {
if (!(map[topX - i][topY + i] && map[topX + i][topY + i]))
return false;
}
for (int i = height / 2 + 2; i <= height; i++) {
int offset = height + 1 - i;
if (!(map[topX - offset][topY + i] && map[topX + offset][topY + i]))
return false;
}
// 3. check inside
for (int i = 1; i <= height / 2 + 1; i++) {
if (sum[topY + i][topX + i] - sum[topY + i][topX - i] != 1) return false;
}
for (int i = height / 2 + 2; i <= height; i++) {
int offset = height + 1 - i;
if (sum[topY + i][topX + offset] - sum[topY + i][topX - offset] != 1) return false;
}
return true;
}
int main() {
std::cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char ch; std::cin >> ch;
map[j][i] = ch == '#';
if (ch == '#') {
sum[i][j] = sum[i][j-1] + 1;
} else {
sum[i][j] = sum[i][j-1];
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (map[j][i] && check2(j, i)) ans++;
}
}
std::cout << ans << std::endl;
return 0;
}