Submission #413595

# Submission time Handle Problem Language Result Execution time Memory
413595 2021-05-29T03:36:35 Z KoD Art Class (IOI13_artclass) C++17
76 / 100
105 ms 10464 KB
#include <bits/stdc++.h>
#include "artclass.h"

template <class T> using Vec = std::vector<T>;

struct UnionFind {
    Vec<int> par;
    int comp;
    UnionFind(const int n): par(n, -1), comp(n) {}
    int find(const int u) {
        return par[u] < 0 ? u : par[u] = find(par[u]);
    }    
    void merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return;
        }
        if (par[x] > par[y]) {
            std::swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        comp -= 1;
    }
};

int solve(const int N, const Vec<int> R, const Vec<int> G, const Vec<int> B, const std::array<int, 4> D) {
    UnionFind dsu(N);
    for (int i = 0; i < N; ++i) {
        for (int k = 0; k < 4; ++k) {
            const auto j = i + D[k];
            if (0 <= j and j < N) {
                if (std::abs(R[i] - R[j]) <= 20 and std::abs(G[i] - G[j]) <= 20 and std::abs(B[i] - B[j]) <= 20) {
                    dsu.merge(i, j);
                }
            }
        }
    }
    if (dsu.comp <= 60) {
        return 4;
    }
    if (dsu.comp >= 30000) {
        return 3;
    }
    int white = 0;
    for (int i = 0; i < N; ++i) {
        if (R[i] >= 200 and G[i] >= 200 and B[i] >= 200) {
            white += 1;
        }
    }
    if (white >= 50000) {
        return 1;
    }
    if (white <= 10) {
        return dsu.comp <= 100 ? 4 : 2;
    }
    // std::cerr << white << ' ' << dsu.comp << std::endl;
    return 2;
}

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    const int N = H * W;
    Vec<int> r(N), g(N), b(N);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            r[i * W + j] = R[i][j];
            g[i * W + j] = G[i][j];
            b[i * W + j] = B[i][j];
        }
    }
    return solve(N, r, g, b, std::array<int, 4>{W, 1, -W, -1});
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8968 KB Output is correct
2 Incorrect 68 ms 7852 KB Output isn't correct
3 Correct 33 ms 4640 KB Output is correct
4 Correct 58 ms 7980 KB Output is correct
5 Incorrect 82 ms 9840 KB Output isn't correct
6 Correct 56 ms 7992 KB Output is correct
7 Correct 74 ms 10436 KB Output is correct
8 Correct 60 ms 8860 KB Output is correct
9 Correct 81 ms 8900 KB Output is correct
10 Incorrect 74 ms 10456 KB Output isn't correct
11 Incorrect 59 ms 9132 KB Output isn't correct
12 Correct 69 ms 9568 KB Output is correct
13 Incorrect 78 ms 9204 KB Output isn't correct
14 Correct 75 ms 9040 KB Output is correct
15 Correct 50 ms 7720 KB Output is correct
16 Incorrect 85 ms 9736 KB Output isn't correct
17 Correct 77 ms 7812 KB Output is correct
18 Correct 59 ms 8828 KB Output is correct
19 Correct 41 ms 4336 KB Output is correct
20 Correct 68 ms 10044 KB Output is correct
21 Correct 63 ms 8516 KB Output is correct
22 Incorrect 48 ms 8288 KB Output isn't correct
23 Correct 59 ms 8260 KB Output is correct
24 Correct 61 ms 9144 KB Output is correct
25 Correct 42 ms 7260 KB Output is correct
26 Incorrect 60 ms 9144 KB Output isn't correct
27 Correct 55 ms 8444 KB Output is correct
28 Incorrect 73 ms 10388 KB Output isn't correct
29 Correct 87 ms 10224 KB Output is correct
30 Correct 65 ms 8784 KB Output is correct
31 Correct 65 ms 9076 KB Output is correct
32 Correct 71 ms 8404 KB Output is correct
33 Correct 71 ms 9576 KB Output is correct
34 Correct 42 ms 7604 KB Output is correct
35 Correct 55 ms 8276 KB Output is correct
36 Correct 59 ms 8936 KB Output is correct
37 Correct 54 ms 8388 KB Output is correct
38 Correct 71 ms 10324 KB Output is correct
39 Correct 36 ms 6752 KB Output is correct
40 Correct 70 ms 8260 KB Output is correct
41 Correct 76 ms 10424 KB Output is correct
42 Correct 38 ms 5572 KB Output is correct
43 Correct 56 ms 9080 KB Output is correct
44 Correct 48 ms 6712 KB Output is correct
45 Correct 42 ms 5584 KB Output is correct
46 Correct 55 ms 8160 KB Output is correct
47 Correct 59 ms 9144 KB Output is correct
48 Correct 73 ms 8820 KB Output is correct
49 Incorrect 73 ms 10464 KB Output isn't correct
50 Correct 45 ms 8008 KB Output is correct
51 Correct 50 ms 7052 KB Output is correct
52 Correct 46 ms 6596 KB Output is correct
53 Correct 49 ms 6908 KB Output is correct
54 Correct 67 ms 8536 KB Output is correct
55 Correct 49 ms 6840 KB Output is correct
56 Correct 59 ms 8420 KB Output is correct
57 Correct 61 ms 8684 KB Output is correct
58 Incorrect 66 ms 9324 KB Output isn't correct
59 Incorrect 65 ms 9248 KB Output isn't correct
60 Correct 69 ms 9996 KB Output is correct
61 Incorrect 16 ms 2380 KB Output isn't correct
62 Correct 63 ms 8680 KB Output is correct
63 Correct 54 ms 8428 KB Output is correct
64 Correct 39 ms 5644 KB Output is correct
65 Correct 60 ms 9184 KB Output is correct
66 Correct 61 ms 9092 KB Output is correct
67 Correct 71 ms 9012 KB Output is correct
68 Correct 59 ms 8132 KB Output is correct
69 Correct 76 ms 9308 KB Output is correct
70 Correct 105 ms 10336 KB Output is correct
71 Correct 30 ms 4300 KB Output is correct
72 Incorrect 48 ms 7840 KB Output isn't correct
73 Incorrect 80 ms 10212 KB Output isn't correct
74 Correct 73 ms 10340 KB Output is correct
75 Correct 57 ms 9232 KB Output is correct
76 Correct 54 ms 9156 KB Output is correct
77 Correct 57 ms 9028 KB Output is correct
78 Correct 56 ms 8192 KB Output is correct
79 Correct 73 ms 10436 KB Output is correct
80 Correct 62 ms 9212 KB Output is correct
81 Correct 48 ms 7920 KB Output is correct
82 Correct 62 ms 8836 KB Output is correct
83 Correct 69 ms 8156 KB Output is correct
84 Incorrect 57 ms 7892 KB Output isn't correct
85 Correct 22 ms 4964 KB Output is correct
86 Incorrect 41 ms 5956 KB Output isn't correct
87 Correct 93 ms 10252 KB Output is correct
88 Correct 40 ms 5596 KB Output is correct
89 Correct 55 ms 7820 KB Output is correct
90 Correct 46 ms 7552 KB Output is correct
91 Correct 61 ms 8728 KB Output is correct
92 Correct 64 ms 8484 KB Output is correct
93 Correct 67 ms 9380 KB Output is correct
94 Correct 61 ms 9396 KB Output is correct
95 Incorrect 61 ms 9092 KB Output isn't correct
96 Correct 50 ms 7524 KB Output is correct
97 Correct 65 ms 9804 KB Output is correct
98 Correct 82 ms 9176 KB Output is correct
99 Incorrect 102 ms 10444 KB Output isn't correct
100 Incorrect 63 ms 9604 KB Output isn't correct
101 Correct 57 ms 8188 KB Output is correct
102 Incorrect 50 ms 8256 KB Output isn't correct