Submission #401885

# Submission time Handle Problem Language Result Execution time Memory
401885 2021-05-10T23:36:00 Z timmyfeng Amusement Park (JOI17_amusement_park) C++17
100 / 100
35 ms 4716 KB
#include <bits/stdc++.h>
using namespace std;
 
#include "Joi.h"

const int L = 60;
 
void Joi(int n, int m, int *a, int *b, long long x, int t) {
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; ++i) {
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
 
    vector<int> id(n, -1), in(n, -1), out(n, INT_MAX), sub;
    auto dfs = [&](int u, auto &self) -> void {
        in[u] = t++;

        sub.push_back(u);

        for (auto c : adj[u]) {
            if (id[c] == -1) {
                int v = -1;
                if ((int) sub.size() == L) {
                    v = *min_element(sub.begin(), sub.end(),
                        [&](int a, int b) {
                            if (out[a] == out[b]) {
                                return in[a] < in[b];
                            } else {
                                return out[a] < out[b];
                            }
                        }
                    );
                    sub.erase(find(sub.begin(), sub.end(), v));
                    id[c] = id[v];
                } else {
                    id[c] = sub.size();
                }

                self(c, self);

                if (v != -1) {
                    sub.erase(find(sub.begin(), sub.end(), c));
                    sub.push_back(v);
                }
            }
        }

        out[u] = t++;
    };
 
    id[0] = 0;
    dfs(0, dfs);

    for (int i = 0; i < n; ++i) {
        MessageBoard(i, (x & (1LL << id[i])) > 0);
    }
}
#include <bits/stdc++.h>
using namespace std;
 
#include "Ioi.h"
 
const int L = 60;
 
long long Ioi(int n, int m, int *a, int *b, int p, int v, int t) {
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; ++i) {
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }

    bool found = false;
    vector<int> id(n, -1), in(n, -1), out(n, INT_MAX), sub;
    auto dfs_find = [&](int u, auto &self) -> bool {
        in[u] = t++;

        found |= u == p;
        sub.push_back(u);
        if (found && (int) sub.size() == L) {
            return true;
        }

        for (auto c : adj[u]) {
            if (id[c] == -1) {
                int v = -1;
                if ((int) sub.size() == L) {
                    v = *min_element(sub.begin(), sub.end(),
                        [&](int a, int b) {
                            if (out[a] == out[b]) {
                                return in[a] < in[b];
                            } else {
                                return out[a] < out[b];
                            }
                        }
                    );
                    sub.erase(find(sub.begin(), sub.end(), v));
                    id[c] = id[v];
                } else {
                    id[c] = sub.size();
                }

                if (self(c, self)) {
                    return true;
                }

                if (v != -1) {
                    sub.erase(find(sub.begin(), sub.end(), c));
                    sub.push_back(v);
                }
            }
        }

        out[u] = t++;

        return false;
    };

    id[0] = 0;
    dfs_find(0, dfs_find);

    long long ans = 0;
    auto dfs_read = [&](int u, auto &self) -> void {
        sub.erase(find(sub.begin(), sub.end(), u));
        ans |= v * (1LL << id[u]);
        for (auto c : adj[u]) {
            if (count(sub.begin(), sub.end(), c) > 0) {
                v = Move(c);
                self(c, self);
                v = Move(u);
            }
        }
    };

    dfs_read(p, dfs_read);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 496 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 3 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 5 ms 948 KB Output is correct
12 Correct 2 ms 496 KB Output is correct
13 Correct 2 ms 756 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4452 KB Output is correct
2 Correct 33 ms 4592 KB Output is correct
3 Correct 30 ms 4532 KB Output is correct
4 Correct 22 ms 2660 KB Output is correct
5 Correct 24 ms 3504 KB Output is correct
6 Correct 23 ms 3300 KB Output is correct
7 Correct 20 ms 3232 KB Output is correct
8 Correct 20 ms 3056 KB Output is correct
9 Correct 22 ms 3480 KB Output is correct
10 Correct 20 ms 2696 KB Output is correct
11 Correct 18 ms 2720 KB Output is correct
12 Correct 18 ms 2436 KB Output is correct
13 Correct 19 ms 2556 KB Output is correct
14 Correct 17 ms 2600 KB Output is correct
15 Correct 20 ms 2716 KB Output is correct
16 Correct 19 ms 2720 KB Output is correct
17 Correct 20 ms 2716 KB Output is correct
18 Correct 19 ms 2732 KB Output is correct
19 Correct 22 ms 2704 KB Output is correct
20 Correct 24 ms 3692 KB Output is correct
21 Correct 19 ms 3672 KB Output is correct
22 Correct 22 ms 3180 KB Output is correct
23 Correct 22 ms 3492 KB Output is correct
24 Correct 22 ms 3288 KB Output is correct
25 Correct 22 ms 3380 KB Output is correct
26 Correct 20 ms 3408 KB Output is correct
27 Correct 19 ms 3192 KB Output is correct
28 Correct 20 ms 3488 KB Output is correct
29 Correct 18 ms 2924 KB Output is correct
30 Correct 19 ms 3200 KB Output is correct
31 Correct 2 ms 500 KB Output is correct
32 Correct 2 ms 508 KB Output is correct
33 Correct 2 ms 732 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 508 KB Output is correct
39 Correct 2 ms 508 KB Output is correct
40 Correct 2 ms 500 KB Output is correct
41 Correct 2 ms 488 KB Output is correct
42 Correct 2 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 628 KB Output is correct
4 Correct 3 ms 1008 KB Output is correct
5 Correct 4 ms 1172 KB Output is correct
6 Correct 4 ms 1040 KB Output is correct
7 Correct 3 ms 1056 KB Output is correct
8 Correct 4 ms 1312 KB Output is correct
9 Correct 18 ms 4124 KB Output is correct
10 Correct 18 ms 3596 KB Output is correct
11 Correct 20 ms 4488 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 496 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4628 KB Output is correct
2 Correct 34 ms 4612 KB Output is correct
3 Correct 32 ms 4716 KB Output is correct
4 Correct 19 ms 2680 KB Output is correct
5 Correct 20 ms 3996 KB Output is correct
6 Correct 19 ms 3100 KB Output is correct
7 Correct 20 ms 3224 KB Output is correct
8 Correct 19 ms 2864 KB Output is correct
9 Correct 20 ms 3104 KB Output is correct
10 Correct 18 ms 2816 KB Output is correct
11 Correct 19 ms 2944 KB Output is correct
12 Correct 18 ms 2580 KB Output is correct
13 Correct 19 ms 2476 KB Output is correct
14 Correct 18 ms 2640 KB Output is correct
15 Correct 20 ms 2708 KB Output is correct
16 Correct 19 ms 2696 KB Output is correct
17 Correct 20 ms 2840 KB Output is correct
18 Correct 20 ms 2716 KB Output is correct
19 Correct 22 ms 2700 KB Output is correct
20 Correct 19 ms 3672 KB Output is correct
21 Correct 19 ms 3664 KB Output is correct
22 Correct 20 ms 3108 KB Output is correct
23 Correct 19 ms 3104 KB Output is correct
24 Correct 20 ms 3248 KB Output is correct
25 Correct 19 ms 3216 KB Output is correct
26 Correct 20 ms 3464 KB Output is correct
27 Correct 20 ms 3536 KB Output is correct
28 Correct 19 ms 2952 KB Output is correct
29 Correct 19 ms 2956 KB Output is correct
30 Correct 18 ms 3096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4428 KB Output is correct
2 Correct 31 ms 4244 KB Output is correct
3 Correct 35 ms 4656 KB Output is correct
4 Correct 20 ms 2732 KB Output is correct
5 Correct 19 ms 3616 KB Output is correct
6 Correct 19 ms 2968 KB Output is correct
7 Correct 20 ms 3076 KB Output is correct
8 Correct 22 ms 3192 KB Output is correct
9 Correct 20 ms 3084 KB Output is correct
10 Correct 17 ms 2716 KB Output is correct
11 Correct 18 ms 2824 KB Output is correct
12 Correct 18 ms 2484 KB Output is correct
13 Correct 18 ms 2604 KB Output is correct
14 Correct 19 ms 2712 KB Output is correct
15 Correct 20 ms 2692 KB Output is correct
16 Correct 19 ms 2716 KB Output is correct
17 Correct 23 ms 2720 KB Output is correct
18 Correct 23 ms 2716 KB Output is correct
19 Correct 20 ms 2692 KB Output is correct
20 Correct 19 ms 3536 KB Output is correct
21 Correct 19 ms 3636 KB Output is correct
22 Correct 20 ms 3156 KB Output is correct
23 Correct 20 ms 3184 KB Output is correct
24 Correct 20 ms 3024 KB Output is correct
25 Correct 20 ms 3128 KB Output is correct
26 Correct 22 ms 3216 KB Output is correct
27 Correct 23 ms 3600 KB Output is correct
28 Correct 19 ms 3356 KB Output is correct
29 Correct 20 ms 3252 KB Output is correct
30 Correct 20 ms 3392 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 752 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 496 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 620 KB Output is correct