Submission #759310

# Submission time Handle Problem Language Result Execution time Memory
759310 2023-06-16T05:40:51 Z drdilyor Keys (IOI21_keys) C++17
37 / 100
3000 ms 24052 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;

struct DSU {
    int n;
    vector<int> parent;
    vector<int> size;
    vector<vector<int>> set;

    DSU(int n) : n(n), parent(n), size(n, 1),set(n) {
        for (int i = 0; i < n ;i++)
            parent[i] = i, set[i] = {i};
    }

    int get(int i) {
        return parent[i] == i ? i : parent[i] = get(parent[i]);
    }

    void merge(int v, int u) {
        v = get(v);
        u = get(u);
        if (u == v) return;
        if (size[v] < size[u]) swap(v, u);
        parent[u] = v;
        size[v] += size[u];
        for (int i : set[u])set[v].push_back(i);
    }
};


vi find_reachable(vi r, vi u, vi v, vi c) {
    int n = r.size();
    int m = u.size();
    vector<vi> byc(n);
    for (int i = 0; i < m; i++)
        byc[c[i]].push_back(i);
    vi count(n);
    for (int root = 0; root < n; root++) {
        DSU cc(n);
        vi obtained(n);
        vi new_keys;
        obtained[r[root]] = 1;
        new_keys.push_back(r[root]);
        while (new_keys.size()) {
            vi keys = std::move(new_keys);
            for (int i : keys) {
                for (int j : byc[i]) {
                    if (cc.get(v[j]) == cc.get(u[j])) continue;
                    if (cc.get(u[j]) == cc.get(root))
                        swap(v[j], u[j]);
                    if (cc.get(v[j]) == cc.get(root)) {
                        for (int k : cc.set[cc.get(u[j])])
                            if (!obtained[r[k]]) {
                                obtained[r[k]] = 1;
                                new_keys.push_back(r[k]);
                            }
                    }
                    cc.merge(v[j], u[j]);
                }
            }
        }
        count[root] = cc.size[cc.get(root)];
    }
    vi ans(n);
    int mn = *min_element(count.begin(), count.end());
    for (int i = 0;i < n;i++)
        ans[i] = count[i] == mn;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 ms 296 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 212 KB Output is correct
26 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 ms 296 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 212 KB Output is correct
26 Correct 3 ms 212 KB Output is correct
27 Correct 191 ms 636 KB Output is correct
28 Correct 189 ms 636 KB Output is correct
29 Correct 185 ms 596 KB Output is correct
30 Correct 44 ms 340 KB Output is correct
31 Correct 33 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 24 ms 452 KB Output is correct
34 Correct 62 ms 452 KB Output is correct
35 Correct 48 ms 436 KB Output is correct
36 Correct 200 ms 576 KB Output is correct
37 Correct 201 ms 572 KB Output is correct
38 Correct 290 ms 624 KB Output is correct
39 Correct 309 ms 624 KB Output is correct
40 Correct 59 ms 468 KB Output is correct
41 Correct 98 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Execution timed out 3031 ms 24052 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 ms 296 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 3 ms 212 KB Output is correct
26 Correct 3 ms 212 KB Output is correct
27 Correct 191 ms 636 KB Output is correct
28 Correct 189 ms 636 KB Output is correct
29 Correct 185 ms 596 KB Output is correct
30 Correct 44 ms 340 KB Output is correct
31 Correct 33 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 24 ms 452 KB Output is correct
34 Correct 62 ms 452 KB Output is correct
35 Correct 48 ms 436 KB Output is correct
36 Correct 200 ms 576 KB Output is correct
37 Correct 201 ms 572 KB Output is correct
38 Correct 290 ms 624 KB Output is correct
39 Correct 309 ms 624 KB Output is correct
40 Correct 59 ms 468 KB Output is correct
41 Correct 98 ms 436 KB Output is correct
42 Execution timed out 3031 ms 24052 KB Time limit exceeded
43 Halted 0 ms 0 KB -