Submission #540145

# Submission time Handle Problem Language Result Execution time Memory
540145 2022-03-19T11:51:55 Z model_code Dijamant (COCI22_dijamant) C++17
70 / 70
227 ms 237400 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 2005;

int n, m, sol;
char c[MAXN][MAXN];
bool bio[MAXN][MAXN];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int mn_sum, mx_sum, mn_dif, mx_dif, ok, cnt;

void dfs (int x, int y) {
    if (x == 0 || x == n + 1 || y == 0 || y == m + 1) {
        ok = 0;
        return;
    }
    if (bio[x][y] || c[x][y] == '#') return;
    bio[x][y] = 1;
    cnt++;

    mn_sum = min(mn_sum, x + y);
    mx_sum = max(mx_sum, x + y);
    mn_dif = min(mn_dif, x - y);
    mx_dif = max(mx_dif, x - y);

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        dfs(nx, ny);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (bio[i][j] || c[i][j] == '#') continue;

            mn_sum = mn_dif = 1e9;
            mx_sum = mx_dif = -1e9;
            ok = 1;
            cnt = 0;

            dfs(i, j);

            if (mx_sum - mn_sum == mx_dif - mn_dif && (mx_sum - mn_sum) % 2 == 0 && ok) {
                int d = (mx_sum - mn_sum) / 2 + 1;
                if (cnt == 2 * d * d - 2 * d + 1) sol++;
            }
        }
    }
    cout << sol;
    return 0;
}
# 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 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 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 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 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 227 ms 237400 KB Output is correct
15 Correct 49 ms 3916 KB Output is correct
16 Correct 147 ms 7672 KB Output is correct
17 Correct 195 ms 162936 KB Output is correct
18 Correct 72 ms 8052 KB Output is correct
19 Correct 124 ms 49796 KB Output is correct
20 Correct 143 ms 42708 KB Output is correct
21 Correct 108 ms 25672 KB Output is correct
22 Correct 121 ms 15484 KB Output is correct
23 Correct 107 ms 14260 KB Output is correct
24 Correct 124 ms 15404 KB Output is correct
25 Correct 209 ms 208060 KB Output is correct
26 Correct 71 ms 7488 KB Output is correct