This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |