#include <bits/stdc++.h>
long a, b, c, d, cnt;
long mini, minj, maxi, maxj;
void dfs(long i, long j, std::vector<std::vector<bool>>& map) {
if (!map[i][j]) return;
a = std::min(a, i + j);
b = std::max(b, i + j);
c = std::min(c, i - j);
d = std::max(d, i - j);
mini = std::min(mini, i);
maxi = std::max(maxi, i);
minj = std::min(minj, j);
maxj = std::max(maxj, j);
map[i][j] = false;
cnt++;
if (i > 0) dfs(i - 1, j, map);
if (i < map.size() - 1) dfs(i + 1, j, map);
if (j > 0) dfs(i, j - 1, map);
if (j < map[0].size() - 1) dfs(i, j + 1, map);
}
int main() {
long n, m;
std::cin >> n >> m;
std::vector<std::vector<bool>> map(n, std::vector<bool>(m, false));
for (size_t i = 0; i < n; i++) {
std::string s;
std::cin >> s;
for (size_t j = 0; j < m; j++) {
map[i][j] = s[j] == '.';
}
}
size_t result = 0;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
a = c = mini = minj = std::numeric_limits<long>::max();
b = d = maxi = maxj = std::numeric_limits<long>::min();
cnt = 0;
dfs(i, j, map);
long s = b - a + 1;
long s1 = s - s / 2;
long s2 = s / 2;
if (cnt == 0 || cnt != s1 * s1 + s2 * s2 || std::abs(b - a) != std::abs(c - d) || mini == 0 || minj == 0 || maxi == n - 1 || maxj == m - 1) continue;
result++;
}
}
std::cout << result << std::endl;
}
Compilation message
Main.cpp: In function 'void dfs(long int, long int, std::vector<std::vector<bool> >&)':
Main.cpp:24:11: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if (i < map.size() - 1) dfs(i + 1, j, map);
| ~~^~~~~~~~~~~~~~~~
Main.cpp:26:11: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (j < map[0].size() - 1) dfs(i, j + 1, map);
| ~~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:36:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'long int' [-Wsign-compare]
36 | for (size_t i = 0; i < n; i++) {
| ~~^~~
Main.cpp:40:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'long int' [-Wsign-compare]
40 | for (size_t j = 0; j < m; j++) {
| ~~^~~
Main.cpp:48:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'long int' [-Wsign-compare]
48 | for (size_t i = 0; i < n; i++) {
| ~~^~~
Main.cpp:49:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'long int' [-Wsign-compare]
49 | for (size_t j = 0; j < m; j++) {
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |