Submission #1065917

# Submission time Handle Problem Language Result Execution time Memory
1065917 2024-08-19T13:07:19 Z ortsac Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1307 ms 998688 KB
#include <bits/stdc++.h>
 
using namespace std;

#define pii pair<int, int>
#define fr first
#define se second

const int MAXT = 4e3 + 10;
char mat[MAXT][MAXT];
bool vis[MAXT][MAXT];

int n, m;
int x[] = {-1, 0, 0, 1};
int y[] = {0, -1, 1, 0};

bool valid(int i, int j) {
    return ((1 <= i) && (n >= i) && (j >= 1) && (j <= m));
}

vector<pii> border;

void dfs(int i, int j) {
    vis[i][j] = 1;
    for (int k = 0; k < 4; k++) {
        int a = (i + x[k]), b = (j + y[k]);
        if (!valid(a, b) || vis[a][b] || (mat[a][b] == '.')) continue;
        if (mat[i][j] != mat[a][b]) border.push_back({a, b});
        else dfs(a, b);
    }
}

int32_t main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> mat[i][j];
        }
    }
    border.push_back({1, 1});
    int ans = 0;
    while (!border.empty()) {
        ans++;
        vector<pii> nb = border;
        border.clear();
        for (auto u : nb) dfs(u.fr, u.se);
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5016 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 700 KB Output is correct
4 Correct 10 ms 6856 KB Output is correct
5 Correct 4 ms 2652 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 4 ms 2504 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 7 ms 2972 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 4 ms 2840 KB Output is correct
15 Correct 16 ms 4864 KB Output is correct
16 Correct 21 ms 5020 KB Output is correct
17 Correct 19 ms 4444 KB Output is correct
18 Correct 11 ms 6872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30544 KB Output is correct
2 Correct 76 ms 11860 KB Output is correct
3 Correct 583 ms 47916 KB Output is correct
4 Correct 375 ms 19024 KB Output is correct
5 Correct 353 ms 33104 KB Output is correct
6 Correct 980 ms 177844 KB Output is correct
7 Correct 14 ms 31956 KB Output is correct
8 Correct 12 ms 30616 KB Output is correct
9 Correct 4 ms 856 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 12 ms 31580 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 77 ms 12112 KB Output is correct
14 Correct 44 ms 8532 KB Output is correct
15 Correct 43 ms 9388 KB Output is correct
16 Correct 34 ms 4444 KB Output is correct
17 Correct 190 ms 20588 KB Output is correct
18 Correct 159 ms 20208 KB Output is correct
19 Correct 150 ms 19024 KB Output is correct
20 Correct 128 ms 17744 KB Output is correct
21 Correct 336 ms 34388 KB Output is correct
22 Correct 358 ms 33016 KB Output is correct
23 Correct 354 ms 27984 KB Output is correct
24 Correct 341 ms 34160 KB Output is correct
25 Correct 624 ms 47884 KB Output is correct
26 Correct 1169 ms 998688 KB Output is correct
27 Correct 1243 ms 818620 KB Output is correct
28 Correct 959 ms 177944 KB Output is correct
29 Correct 979 ms 225740 KB Output is correct
30 Correct 997 ms 325272 KB Output is correct
31 Correct 788 ms 38408 KB Output is correct
32 Correct 1307 ms 480368 KB Output is correct