Submission #892532

# Submission time Handle Problem Language Result Execution time Memory
892532 2023-12-25T13:18:06 Z vanea Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
1053 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 4e3+10;

char matrix[mxN][mxN];
bool vis[mxN][mxN];
int n, m;

vector<int> xy = {1, 0, -1, 0}, yx = {0, 1, 0, -1};

int add = 1;

void dfs(int x, int y) {
    char c = matrix[x][y];
    vis[x][y] = true;
    for(int i = 0; i < 4; i++) {
        int a = x + xy[i], b = y + yx[i];
        if(a >= 0 && a < n && b >= 0 && b < m && !vis[a][b]) {
            if(matrix[a][b] == c){
                dfs(a, b);
            }
            if(matrix[a][b] != c && matrix[a][b] != '.') {
                add = 2;
                dfs(a, b);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> matrix[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(matrix[i][j] != '.' && !vis[i][j]) {
                dfs(i, j);
                ans += add;
                add = 1;
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23128 KB Output isn't correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Incorrect 1 ms 2516 KB Output isn't correct
4 Incorrect 15 ms 18524 KB Output isn't correct
5 Incorrect 5 ms 6492 KB Output isn't correct
6 Incorrect 1 ms 2512 KB Output isn't correct
7 Incorrect 1 ms 2652 KB Output isn't correct
8 Incorrect 1 ms 2908 KB Output isn't correct
9 Incorrect 1 ms 2904 KB Output isn't correct
10 Incorrect 4 ms 5724 KB Output isn't correct
11 Incorrect 5 ms 6236 KB Output isn't correct
12 Incorrect 7 ms 11268 KB Output isn't correct
13 Incorrect 3 ms 6492 KB Output isn't correct
14 Incorrect 5 ms 6492 KB Output isn't correct
15 Incorrect 14 ms 10328 KB Output isn't correct
16 Incorrect 20 ms 23132 KB Output isn't correct
17 Incorrect 11 ms 11612 KB Output isn't correct
18 Incorrect 14 ms 18524 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 32572 KB Output isn't correct
2 Incorrect 39 ms 17292 KB Output isn't correct
3 Incorrect 329 ms 164548 KB Output isn't correct
4 Incorrect 83 ms 45720 KB Output isn't correct
5 Incorrect 408 ms 387500 KB Output isn't correct
6 Runtime error 937 ms 1048576 KB Execution killed with signal 9
7 Incorrect 12 ms 32600 KB Output isn't correct
8 Incorrect 9 ms 32348 KB Output isn't correct
9 Incorrect 2 ms 3852 KB Output isn't correct
10 Incorrect 1 ms 2908 KB Output isn't correct
11 Incorrect 9 ms 31956 KB Output isn't correct
12 Incorrect 2 ms 3932 KB Output isn't correct
13 Incorrect 38 ms 17376 KB Output isn't correct
14 Incorrect 22 ms 13648 KB Output isn't correct
15 Incorrect 32 ms 33628 KB Output isn't correct
16 Incorrect 19 ms 10128 KB Output isn't correct
17 Incorrect 87 ms 29000 KB Output isn't correct
18 Incorrect 132 ms 108744 KB Output isn't correct
19 Incorrect 89 ms 45904 KB Output isn't correct
20 Incorrect 72 ms 43604 KB Output isn't correct
21 Incorrect 184 ms 101184 KB Output isn't correct
22 Incorrect 380 ms 387380 KB Output isn't correct
23 Incorrect 162 ms 42832 KB Output isn't correct
24 Incorrect 302 ms 270572 KB Output isn't correct
25 Incorrect 574 ms 404184 KB Output isn't correct
26 Correct 1049 ms 1001428 KB Output is correct
27 Runtime error 800 ms 1048576 KB Execution killed with signal 9
28 Runtime error 849 ms 1048576 KB Execution killed with signal 9
29 Runtime error 847 ms 1048576 KB Execution killed with signal 9
30 Runtime error 854 ms 1048576 KB Execution killed with signal 9
31 Incorrect 961 ms 814160 KB Output isn't correct
32 Incorrect 1053 ms 869208 KB Output isn't correct