Submission #1065802

# Submission time Handle Problem Language Result Execution time Memory
1065802 2024-08-19T11:53:18 Z ortsac Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
1298 ms 220532 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];
pii dad[MAXT][MAXT];
int tam[MAXT][MAXT];
int cR = 0, cF = 0;

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));
}

pii find(pii x) {
    if (dad[x.fr][x.se] == x) return x;
    return dad[x.fr][x.se] = find(dad[x.fr][x.se]);
}

void print(pii a) {
    cout << a.fr << " " << a.se << "\n";
}

void join(pii a, pii b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (tam[a.fr][a.se] > tam[b.fr][b.se]) swap(a, b);
    tam[b.fr][b.se] += tam[a.fr][a.se];
    dad[a.fr][a.se] = 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];
            if (mat[i][j] != '.') {
                tam[i][j] = 1;
                dad[i][j] = {i, j};
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mat[i][j] == '.') continue;
            for (int k = 0; k < 4; k++) {
                int a = i + x[k], b = j + y[k];
                if ((!valid(a, b)) || (mat[i][j] != mat[a][b])) continue;
                join({i, j}, {a, b});
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mat[i][j] == '.') continue;
            if (dad[i][j] != make_pair(i, j)) continue;
            if (mat[i][j] == 'R') cR++;
            else cF++;
        }
    }
    cout << min(cR, cF) + 1 << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 18776 KB Output isn't correct
2 Incorrect 1 ms 6744 KB Output isn't correct
3 Incorrect 1 ms 10584 KB Output isn't correct
4 Incorrect 13 ms 16956 KB Output isn't correct
5 Incorrect 6 ms 14172 KB Output isn't correct
6 Incorrect 1 ms 6492 KB Output isn't correct
7 Incorrect 1 ms 10588 KB Output isn't correct
8 Incorrect 2 ms 10756 KB Output isn't correct
9 Incorrect 2 ms 10588 KB Output isn't correct
10 Incorrect 4 ms 13660 KB Output isn't correct
11 Incorrect 5 ms 13148 KB Output isn't correct
12 Incorrect 8 ms 12892 KB Output isn't correct
13 Incorrect 5 ms 14172 KB Output isn't correct
14 Incorrect 5 ms 14136 KB Output isn't correct
15 Incorrect 17 ms 17240 KB Output isn't correct
16 Incorrect 20 ms 17724 KB Output isn't correct
17 Incorrect 15 ms 17500 KB Output isn't correct
18 Incorrect 14 ms 16732 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 55644 KB Output isn't correct
2 Incorrect 90 ms 32852 KB Output isn't correct
3 Incorrect 621 ms 138172 KB Output isn't correct
4 Incorrect 167 ms 73208 KB Output isn't correct
5 Incorrect 317 ms 109856 KB Output isn't correct
6 Incorrect 1251 ms 220532 KB Output isn't correct
7 Incorrect 17 ms 57180 KB Output isn't correct
8 Incorrect 16 ms 55644 KB Output isn't correct
9 Incorrect 4 ms 6748 KB Output isn't correct
10 Incorrect 2 ms 4444 KB Output isn't correct
11 Incorrect 16 ms 56740 KB Output isn't correct
12 Incorrect 2 ms 12632 KB Output isn't correct
13 Incorrect 82 ms 34240 KB Output isn't correct
14 Incorrect 57 ms 25724 KB Output isn't correct
15 Incorrect 50 ms 33136 KB Output isn't correct
16 Incorrect 36 ms 19288 KB Output isn't correct
17 Incorrect 198 ms 58612 KB Output isn't correct
18 Incorrect 193 ms 80460 KB Output isn't correct
19 Incorrect 164 ms 73140 KB Output isn't correct
20 Incorrect 140 ms 53392 KB Output isn't correct
21 Incorrect 365 ms 101968 KB Output isn't correct
22 Incorrect 323 ms 110676 KB Output isn't correct
23 Incorrect 355 ms 89844 KB Output isn't correct
24 Incorrect 345 ms 97868 KB Output isn't correct
25 Incorrect 766 ms 220500 KB Output isn't correct
26 Correct 945 ms 194132 KB Output is correct
27 Incorrect 1298 ms 220496 KB Output isn't correct
28 Incorrect 1275 ms 220500 KB Output isn't correct
29 Incorrect 1224 ms 220496 KB Output isn't correct
30 Incorrect 1155 ms 218708 KB Output isn't correct
31 Incorrect 794 ms 169556 KB Output isn't correct
32 Incorrect 1149 ms 220496 KB Output isn't correct