#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int oo = 1e9;
int n, m, sol;
char a[2020][2020];
bool vis[2020][2020];
int min_sm, max_sm, min_diff, max_diff, check, cnt;
void dfs(int x, int y)
{
if ((x == 0) || (x == n + 1) || (y == 0) || (y == m + 1))
{
check = 0;
return;
}
if (vis[x][y] || a[x][y] == '#')
return;
vis[x][y] = 1;
cnt++;
min_sm = min(min_sm, x + y);
max_sm = max(max_sm, x + y);
min_diff = min(min_diff, x - y);
max_diff = max(max_diff, x - y);
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
dfs(nx, ny);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if (fopen("DIAMOND.inp", "r"))
{
freopen("DIAMOND.inp", "r", stdin);
freopen("DIAMOND.out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
ll sol = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (vis[i][j] || a[i][j] == '#')
continue;
min_sm = min_diff = oo;
max_sm = max_diff = -oo;
check = 1;
cnt = 0;
dfs(i, j);
if (max_sm - min_sm == max_diff - min_diff && (max_sm - min_sm) % 2 == 0 && check)
{
int d = (max_sm - min_sm) / 2 + 1;
if (cnt == 2 * d * d - 2 * d + 1)
sol++;
}
}
cout << sol;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen("DIAMOND.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen("DIAMOND.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
728 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
728 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
211 ms |
240984 KB |
Output is correct |
15 |
Correct |
37 ms |
7728 KB |
Output is correct |
16 |
Correct |
102 ms |
11084 KB |
Output is correct |
17 |
Correct |
175 ms |
166384 KB |
Output is correct |
18 |
Correct |
55 ms |
12000 KB |
Output is correct |
19 |
Correct |
133 ms |
53204 KB |
Output is correct |
20 |
Correct |
122 ms |
46656 KB |
Output is correct |
21 |
Correct |
121 ms |
28964 KB |
Output is correct |
22 |
Correct |
111 ms |
19028 KB |
Output is correct |
23 |
Correct |
127 ms |
17720 KB |
Output is correct |
24 |
Correct |
124 ms |
19120 KB |
Output is correct |
25 |
Correct |
197 ms |
211296 KB |
Output is correct |
26 |
Correct |
71 ms |
10884 KB |
Output is correct |