Submission #667951

# Submission time Handle Problem Language Result Execution time Memory
667951 2022-12-02T12:09:22 Z bashkort Amusement Park (JOI17_amusement_park) C++17
96 / 100
24 ms 5724 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

void Joi(int N, int M, int A[], int B[], long long X, int T) {
    struct DSU {
        vector<int> p;
        DSU() = default;
        DSU(int n) : p(n) {
            iota(p.begin(), p.end(), 0);
        }

        int leader(int x) {
            while (x != p[x]) x = p[x] = p[p[x]];
            return x;
        }

        bool unite(int x, int y) {
            x = leader(x), y = leader(y);
            if (p[y] == x) {
                return false;
            } else {
                return p[y] = x, true;
            }
        }
    };

    mt19937 rnd(228);
    vector<pair<int, int>> edges(M);
    for (int i = 0; i < M; ++i) {
        edges[i] = {A[i], B[i]};
    }
    shuffle(edges.begin(), edges.end(), rnd);
    vector<int> tin(N), par(N, -1);
    vector<vector<int>> g(N), adj(N);
    DSU d(N);
    for (int i = 0; i < M; ++i) {
        auto [a, b] = edges[i];
        if (d.unite(a, b)) {
            g[a].push_back(b);
            g[b].push_back(a);
        }
    }

    int timer = 0;
    function<void(int)> dfs = [&](int v) {
        tin[v] = timer++;
        sort(g[v].begin(), g[v].end());
        for (int to : g[v]) {
            if (to != par[v]) {
                par[to] = v;
                adj[v].push_back(to);
                dfs(to);
            }
        }
    };
    dfs(228 % N);

    for (int i = 0; i < N; ++i) {
        MessageBoard(i, X >> (tin[i] % 60) & 1);
    }
}
#include "Ioi.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;


long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    struct DSU {
        vector<int> p;

        DSU() = default;

        DSU(int n) : p(n) {
            iota(p.begin(), p.end(), 0);
        }

        int leader(int x) {
            while (x != p[x]) x = p[x] = p[p[x]];
            return x;
        }

        bool unite(int x, int y) {
            x = leader(x), y = leader(y);
            if (p[y] == x) {
                return false;
            } else {
                return p[y] = x, true;
            }
        }
    };

    mt19937 rnd(228);
    vector<pair<int, int>> edges(M);
    for (int i = 0; i < M; ++i) {
        edges[i] = {A[i], B[i]};
    }
    shuffle(edges.begin(), edges.end(), rnd);
    vector<int> tin(N), par(N, -1), tout(N);
    vector<vector<int>> g(N), adj(N);
    DSU d(N);
    for (int i = 0; i < M; ++i) {
        auto [a, b] = edges[i];
        if (d.unite(a, b)) {
            g[a].push_back(b);
            g[b].push_back(a);
        }
    }

    int timer = 0;
    function<void(int)> dfs = [&](int v) {
        tin[v] = timer++;
        sort(g[v].begin(), g[v].end());
        for (int to: g[v]) {
            if (to != par[v]) {
                par[to] = v;
                adj[v].push_back(to);
                dfs(to);
            }
        }
        tout[v] = timer;
    };
    dfs(228 % N);
    int LOG = 60;
    vector<bool> used(N);
    vector<int> ans(LOG, -1);
    ans[tin[P] % LOG] = V;
    vector<int> last(N, -1);
    int x = P;
    auto any = [&](int l, int r) {
        if (l >= r) {
            return (r && find(ans.begin(), ans.begin() + r, -1) != (ans.begin() + r))
                   || (find(ans.begin() + l, ans.end(), -1) != ans.end());
        }
        return find(ans.begin() + l, ans.begin() + r, -1) != (ans.begin() + r);
    };
    while (any(0, LOG)) {
        used[x] = true;
        auto it = upper_bound(adj[x].begin(), adj[x].end(), last[x]);
        if (it == adj[x].end()) {
            it = adj[x].begin();
        }
        if (adj[x].empty() || used[*it]) {
            last[par[x]] = x;
            x = par[x];
            assert(x != -1);
            ans[tin[x] % LOG] = Move(x);
        } else {
            last[x] = *it;
            int to = *it;
            if (any(tin[to] % 60, tout[to] % 60)) {
                x = *it;
                ans[tin[x] % LOG] = Move(x);
            } else {
                adj[x].erase(lower_bound(adj[x].begin(), adj[x].end(), to));
            }
        }
    }

    ll X = 0;
    for (int i = 0; i < LOG; ++i) {
        assert(ans[i] != -1);
        X += ans[i] * (1LL << i);
    }

    return X;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 772 KB Output is correct
4 Correct 1 ms 648 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 780 KB Output is correct
8 Correct 2 ms 784 KB Output is correct
9 Correct 2 ms 780 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 6 ms 944 KB Output is correct
12 Correct 2 ms 520 KB Output is correct
13 Correct 2 ms 776 KB Output is correct
14 Correct 1 ms 776 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 2 ms 772 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4316 KB Output is correct
2 Correct 24 ms 4172 KB Output is correct
3 Correct 23 ms 4140 KB Output is correct
4 Correct 15 ms 3668 KB Output is correct
5 Correct 16 ms 5440 KB Output is correct
6 Correct 16 ms 4180 KB Output is correct
7 Correct 16 ms 4268 KB Output is correct
8 Correct 17 ms 4436 KB Output is correct
9 Correct 15 ms 4164 KB Output is correct
10 Correct 13 ms 3484 KB Output is correct
11 Correct 14 ms 3620 KB Output is correct
12 Correct 14 ms 3280 KB Output is correct
13 Correct 13 ms 3264 KB Output is correct
14 Correct 13 ms 3344 KB Output is correct
15 Correct 15 ms 3800 KB Output is correct
16 Correct 18 ms 3920 KB Output is correct
17 Correct 14 ms 3684 KB Output is correct
18 Correct 16 ms 3672 KB Output is correct
19 Correct 16 ms 3660 KB Output is correct
20 Correct 14 ms 4468 KB Output is correct
21 Correct 13 ms 4440 KB Output is correct
22 Correct 15 ms 4436 KB Output is correct
23 Correct 14 ms 4272 KB Output is correct
24 Correct 15 ms 4048 KB Output is correct
25 Correct 14 ms 4316 KB Output is correct
26 Correct 16 ms 4180 KB Output is correct
27 Correct 15 ms 4436 KB Output is correct
28 Correct 14 ms 4412 KB Output is correct
29 Correct 14 ms 3788 KB Output is correct
30 Correct 14 ms 3852 KB Output is correct
31 Correct 0 ms 512 KB Output is correct
32 Correct 1 ms 776 KB Output is correct
33 Correct 1 ms 776 KB Output is correct
34 Correct 2 ms 520 KB Output is correct
35 Correct 2 ms 520 KB Output is correct
36 Correct 2 ms 652 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 524 KB Output is correct
39 Correct 1 ms 520 KB Output is correct
40 Correct 0 ms 520 KB Output is correct
41 Correct 1 ms 648 KB Output is correct
42 Correct 1 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 520 KB Output is correct
3 Correct 1 ms 524 KB Output is correct
4 Correct 5 ms 1308 KB Output is correct
5 Correct 4 ms 1316 KB Output is correct
6 Correct 2 ms 1316 KB Output is correct
7 Correct 2 ms 1308 KB Output is correct
8 Correct 2 ms 1308 KB Output is correct
9 Correct 13 ms 5588 KB Output is correct
10 Correct 14 ms 5724 KB Output is correct
11 Correct 13 ms 5724 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 652 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 0 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4344 KB Output is correct
2 Partially correct 20 ms 4316 KB Partially correct
3 Correct 22 ms 4324 KB Output is correct
4 Correct 15 ms 3672 KB Output is correct
5 Correct 16 ms 4996 KB Output is correct
6 Correct 17 ms 4320 KB Output is correct
7 Correct 18 ms 4400 KB Output is correct
8 Correct 15 ms 4044 KB Output is correct
9 Correct 15 ms 4356 KB Output is correct
10 Correct 13 ms 3476 KB Output is correct
11 Correct 14 ms 3548 KB Output is correct
12 Correct 13 ms 3260 KB Output is correct
13 Correct 13 ms 3200 KB Output is correct
14 Correct 14 ms 3408 KB Output is correct
15 Correct 17 ms 3736 KB Output is correct
16 Correct 17 ms 3804 KB Output is correct
17 Correct 15 ms 3696 KB Output is correct
18 Correct 14 ms 3664 KB Output is correct
19 Correct 15 ms 3664 KB Output is correct
20 Correct 13 ms 4432 KB Output is correct
21 Correct 13 ms 4408 KB Output is correct
22 Correct 18 ms 4140 KB Output is correct
23 Correct 14 ms 4184 KB Output is correct
24 Correct 15 ms 4228 KB Output is correct
25 Correct 15 ms 4160 KB Output is correct
26 Correct 19 ms 4044 KB Output is correct
27 Correct 15 ms 4176 KB Output is correct
28 Correct 14 ms 4220 KB Output is correct
29 Correct 14 ms 3884 KB Output is correct
30 Correct 14 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4460 KB Output is correct
2 Correct 22 ms 4196 KB Output is correct
3 Correct 23 ms 4100 KB Output is correct
4 Correct 15 ms 3668 KB Output is correct
5 Correct 15 ms 5080 KB Output is correct
6 Correct 15 ms 4444 KB Output is correct
7 Correct 15 ms 4436 KB Output is correct
8 Correct 15 ms 4160 KB Output is correct
9 Correct 16 ms 3988 KB Output is correct
10 Correct 14 ms 3556 KB Output is correct
11 Correct 15 ms 3536 KB Output is correct
12 Correct 13 ms 3272 KB Output is correct
13 Correct 13 ms 3404 KB Output is correct
14 Correct 13 ms 3444 KB Output is correct
15 Correct 14 ms 3804 KB Output is correct
16 Correct 14 ms 3792 KB Output is correct
17 Correct 15 ms 3664 KB Output is correct
18 Correct 15 ms 3652 KB Output is correct
19 Correct 16 ms 3580 KB Output is correct
20 Correct 12 ms 4444 KB Output is correct
21 Correct 13 ms 4440 KB Output is correct
22 Correct 14 ms 4168 KB Output is correct
23 Correct 15 ms 4432 KB Output is correct
24 Correct 14 ms 4180 KB Output is correct
25 Correct 15 ms 4304 KB Output is correct
26 Correct 15 ms 4160 KB Output is correct
27 Correct 15 ms 4440 KB Output is correct
28 Correct 16 ms 4288 KB Output is correct
29 Correct 17 ms 4168 KB Output is correct
30 Correct 19 ms 3912 KB Output is correct
31 Correct 1 ms 520 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 2 ms 780 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 0 ms 520 KB Output is correct
36 Correct 1 ms 512 KB Output is correct
37 Correct 0 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 0 ms 512 KB Output is correct
40 Correct 0 ms 516 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 2 ms 520 KB Output is correct