Submission #911027

# Submission time Handle Problem Language Result Execution time Memory
911027 2024-01-18T11:27:25 Z gawr_gura Stray Cat (JOI20_stray) C++17
100 / 100
40 ms 16248 KB
#include "Anthony.h"

#include <bits/stdc++.h>
using namespace std;

namespace std {

template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
        static_assert(D >= 1, "Dimension must be positive");
        template <typename... Args>
        Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};

template <typename T>
struct Vec<1, T> : public vector<T> {
        Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {}
};

/* Example
        Vec<4, int64_t> f(n, k, 2, 2); // = f[n][k][2][2];
        Vec<2, int> adj(n); // graph
*/

template <class Fun>
class y_combinator_result {
        Fun fun_;

       public:
        template <class T>
        explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}

        template <class... Args>
        decltype(auto) operator()(Args &&...args) {
                return fun_(std::ref(*this), std::forward<Args>(args)...);
        }
};

template <class Fun>
decltype(auto) y_combinator(Fun &&fun) {
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

/* Example
        auto fun = y_combinator([&](auto self, int x) -> void {
                self(x + 1);
        });
*/

}  // namespace std

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
        vector<vector<pair<int, int>>> adj(N);
        for (int i = 0; i < M; i++) adj[U[i]].emplace_back(V[i], i);
        for (int i = 0; i < M; i++) adj[V[i]].emplace_back(U[i], i);
        vector<int> depth(M, -1);
        vector<int> d(N, -1);
        if (A == 4) A = 3;
        if (A == 3) {
                queue<int> q;
                q.emplace(0);
                d[0] = 0;
                while (q.size()) {
                        int u = q.front();
                        q.pop();
                        for (auto &&[v, i] : adj[u]) {
                                if (d[v] == -1) {
                                        d[v] = d[u] + 1;
                                        depth[i] = d[u];
                                        q.emplace(v);
                                }
                        }
                }

                vector<int> ans(M);
                for (int i = 0; i < M; i++) {
                        if (depth[i] == -1) {
                                if (d[U[i]] == d[V[i]]) {
                                        ans[i] = d[U[i]] % 3;
                                } else {
                                        ans[i] = min(d[U[i]], d[V[i]]) % 3;
                                }
                        } else {
                                ans[i] = depth[i] % 3;
                        }
                }

                return ans;
        } else {
                vector<int> base({0, 1, 1, 0, 0, 1});
                vector<int> deg(N);
                for (int i = 0; i < M; i++) deg[U[i]]++, deg[V[i]]++;
                queue<int> q;
                q.emplace(0);
                d[0] = 0;
                vector<int> par(N);
                vector<int> ans(M);
                while (q.size()) {
                        int u = q.front();
                        q.pop();
                        for (auto &&[v, i] : adj[u]) {
                                if (d[v] == -1) {
                                        d[v] = d[u] + 1;
                                        if (u == 0 || deg[u] == 2) {
                                        } else {
                                                for (int j = 0; j < 6; j++) {
                                                        if (base[(666666 - j) % 6] != base[par[u]]) d[v] = j;
                                                }
                                        }
                                        ans[i] = (666666 - d[v]) % 6;
                                        par[v] = ans[i];
                                        q.emplace(v);
                                }
                        }
                }

                for (int i = 0; i < M; i++) ans[i] = base[ans[i]];

                return ans;
        }
}
#include "Catherine.h"

#include <bits/stdc++.h>
using namespace std;

namespace std {

template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
        static_assert(D >= 1, "Dimension must be positive");
        template <typename... Args>
        Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};

template <typename T>
struct Vec<1, T> : public vector<T> {
        Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {}
};

/* Example
        Vec<4, int64_t> f(n, k, 2, 2); // = f[n][k][2][2];
        Vec<2, int> adj(n); // graph
*/

template <class Fun>
class y_combinator_result {
        Fun fun_;

       public:
        template <class T>
        explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}

        template <class... Args>
        decltype(auto) operator()(Args &&...args) {
                return fun_(std::ref(*this), std::forward<Args>(args)...);
        }
};

template <class Fun>
decltype(auto) y_combinator(Fun &&fun) {
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

/* Example
        auto fun = y_combinator([&](auto self, int x) -> void {
                self(x + 1);
        });
*/

}  // namespace std

namespace {

int A, B;
stack<int> st;
int last = -1;
vector<int> base({0, 1, 1, 0, 0, 1});
vector<int> possible;
bool good = 0;

}  // namespace

void Init(int A, int B) {
        ::A = A;
        ::A = min(::A, 3);
        ::B = B;
        possible.resize(6);
        iota(possible.begin(), possible.end(), 0);
}

int Move(std::vector<int> y) {
        if (A == 3) {
                int cnt = 0;
                for (int i = 0; i < A; i++) {
                        cnt += y[i] > 0;
                }
                if (cnt == 1) {
                        for (int i = 0; i < A; i++) {
                                if (y[i] > 0) return i;
                        }
                } else {
                        for (int i = 0; i < A; i++) {
                                if (y[i] > 0 && y[(i + 1) % A] > 0) return i;
                        }
                }
        } else {
                if (last != -1) y[last]++;
                int cnt = 0;
                int xam = 0;
                for (int i = 0; i < A; i++) {
                        xam = max(xam, y[i]);
                        cnt += y[i] > 0;
                }
                int nxt = -1;
                if (xam > 1 && cnt > 1) {
                        good = 1;
                        for (int i = 0; i < A; i++) {
                                if (y[i] == 1) {
                                        int ans = last == i ? -1 : i;
                                        last = i;
                                        return ans;
                                }
                        }
                } else {
                        if (cnt == 1) {
                                for (int i = 0; i < A; i++) {
                                        if (y[i] == 1) {
                                                good = 1;
                                                int ans = last == i ? -1 : i;
                                                last = i;
                                                return ans;
                                        }
                                }
                                for (int i = 0; i < A; i++) {
                                        if (y[i] > 0) nxt = i;
                                }
                                if (good) {
                                        last = nxt;
                                        return nxt;
                                }
                                goto check;
                        } else {
                                if (good) {
                                        last ^= 1;
                                        return last;
                                } else {
                                        goto check;
                                }
                        }
                }
        check:;

                if (nxt == -1) {
                        if (last == -1) {
                                vector<int> npo;
                                for (int i : possible) {
                                        if (base[(i + 1) % 6] == 0) npo.emplace_back((i + 1) % 6);
                                }
                                possible.swap(npo);
                                nxt = 1;
                        } else {
                                nxt = cnt == 1 ? last : (last ^ 1);
                        }
                } else {
                        if (last == -1) {
                                vector<int> npo;
                                for (int i : possible) {
                                        if (base[(i + 1) % 6] == nxt) npo.emplace_back((i + 1) % 6);
                                }
                                possible.swap(npo);
                        }
                }
                vector<int> npo;
                for (int i : possible) {
                        if (base[(i + 1) % 6] == nxt) npo.emplace_back((i + 1) % 6);
                }
                possible.swap(npo);
                if (possible.size() == 0) {
                        good = 1;
                        return -1;
                } else {
                        last = nxt;
                        return nxt;
                }
        }
}

Compilation message

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:166:1: warning: control reaches end of non-void function [-Wreturn-type]
  166 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 30 ms 15492 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 26 ms 14724 KB Output is correct
4 Correct 36 ms 16248 KB Output is correct
5 Correct 37 ms 16216 KB Output is correct
6 Correct 30 ms 15200 KB Output is correct
7 Correct 31 ms 15272 KB Output is correct
8 Correct 34 ms 15948 KB Output is correct
9 Correct 36 ms 15996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 15492 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 26 ms 14724 KB Output is correct
4 Correct 36 ms 16248 KB Output is correct
5 Correct 37 ms 16216 KB Output is correct
6 Correct 30 ms 15200 KB Output is correct
7 Correct 31 ms 15272 KB Output is correct
8 Correct 34 ms 15948 KB Output is correct
9 Correct 36 ms 15996 KB Output is correct
10 Correct 26 ms 13296 KB Output is correct
11 Correct 26 ms 13288 KB Output is correct
12 Correct 26 ms 13288 KB Output is correct
13 Correct 27 ms 13304 KB Output is correct
14 Correct 27 ms 13468 KB Output is correct
15 Correct 30 ms 13948 KB Output is correct
16 Correct 33 ms 15784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 13012 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 25 ms 12244 KB Output is correct
4 Correct 34 ms 14232 KB Output is correct
5 Correct 34 ms 14240 KB Output is correct
6 Correct 28 ms 12936 KB Output is correct
7 Correct 26 ms 12912 KB Output is correct
8 Correct 32 ms 13696 KB Output is correct
9 Correct 32 ms 13684 KB Output is correct
10 Correct 34 ms 13352 KB Output is correct
11 Correct 30 ms 13436 KB Output is correct
12 Correct 30 ms 13440 KB Output is correct
13 Correct 30 ms 13444 KB Output is correct
14 Correct 38 ms 13620 KB Output is correct
15 Correct 33 ms 13704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 13012 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 25 ms 12244 KB Output is correct
4 Correct 34 ms 14232 KB Output is correct
5 Correct 34 ms 14240 KB Output is correct
6 Correct 28 ms 12936 KB Output is correct
7 Correct 26 ms 12912 KB Output is correct
8 Correct 32 ms 13696 KB Output is correct
9 Correct 32 ms 13684 KB Output is correct
10 Correct 34 ms 13352 KB Output is correct
11 Correct 30 ms 13436 KB Output is correct
12 Correct 30 ms 13440 KB Output is correct
13 Correct 30 ms 13444 KB Output is correct
14 Correct 38 ms 13620 KB Output is correct
15 Correct 33 ms 13704 KB Output is correct
16 Correct 26 ms 11356 KB Output is correct
17 Correct 24 ms 11480 KB Output is correct
18 Correct 27 ms 11232 KB Output is correct
19 Correct 25 ms 11240 KB Output is correct
20 Correct 28 ms 11752 KB Output is correct
21 Correct 27 ms 11760 KB Output is correct
22 Correct 31 ms 13688 KB Output is correct
23 Correct 28 ms 11488 KB Output is correct
24 Correct 26 ms 11532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 2 ms 792 KB Output is correct
3 Correct 2 ms 1048 KB Output is correct
4 Correct 2 ms 1056 KB Output is correct
5 Correct 2 ms 1052 KB Output is correct
6 Correct 2 ms 1052 KB Output is correct
7 Correct 2 ms 1044 KB Output is correct
8 Correct 2 ms 1052 KB Output is correct
9 Correct 2 ms 1044 KB Output is correct
10 Correct 2 ms 1044 KB Output is correct
11 Correct 2 ms 1044 KB Output is correct
12 Correct 2 ms 1044 KB Output is correct
13 Correct 2 ms 1036 KB Output is correct
14 Correct 2 ms 1044 KB Output is correct
15 Correct 2 ms 1048 KB Output is correct
16 Correct 2 ms 1044 KB Output is correct
17 Correct 2 ms 1044 KB Output is correct
18 Correct 2 ms 1044 KB Output is correct
19 Correct 2 ms 1048 KB Output is correct
20 Correct 2 ms 1504 KB Output is correct
21 Correct 2 ms 1036 KB Output is correct
22 Correct 2 ms 1052 KB Output is correct
23 Correct 2 ms 1056 KB Output is correct
24 Correct 2 ms 1044 KB Output is correct
25 Correct 2 ms 1044 KB Output is correct
26 Correct 2 ms 1044 KB Output is correct
27 Correct 2 ms 1052 KB Output is correct
28 Correct 2 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11384 KB Output is correct
2 Correct 35 ms 11620 KB Output is correct
3 Correct 1 ms 780 KB Output is correct
4 Correct 22 ms 11368 KB Output is correct
5 Correct 32 ms 12408 KB Output is correct
6 Correct 33 ms 12372 KB Output is correct
7 Correct 27 ms 11356 KB Output is correct
8 Correct 35 ms 11444 KB Output is correct
9 Correct 32 ms 12340 KB Output is correct
10 Correct 32 ms 12468 KB Output is correct
11 Correct 32 ms 12416 KB Output is correct
12 Correct 33 ms 12252 KB Output is correct
13 Correct 32 ms 12412 KB Output is correct
14 Correct 34 ms 12208 KB Output is correct
15 Correct 32 ms 12388 KB Output is correct
16 Correct 32 ms 12372 KB Output is correct
17 Correct 38 ms 12076 KB Output is correct
18 Correct 30 ms 11928 KB Output is correct
19 Correct 30 ms 12160 KB Output is correct
20 Correct 28 ms 12156 KB Output is correct
21 Correct 32 ms 12064 KB Output is correct
22 Correct 30 ms 12152 KB Output is correct
23 Correct 27 ms 11356 KB Output is correct
24 Correct 27 ms 11172 KB Output is correct
25 Correct 33 ms 11172 KB Output is correct
26 Correct 27 ms 11260 KB Output is correct
27 Correct 30 ms 11948 KB Output is correct
28 Correct 30 ms 11708 KB Output is correct
29 Correct 30 ms 11868 KB Output is correct
30 Correct 38 ms 11940 KB Output is correct
31 Correct 27 ms 11216 KB Output is correct
32 Correct 26 ms 11236 KB Output is correct
33 Correct 27 ms 11256 KB Output is correct
34 Correct 26 ms 11428 KB Output is correct
35 Correct 28 ms 11620 KB Output is correct
36 Correct 30 ms 11692 KB Output is correct
37 Correct 34 ms 11780 KB Output is correct
38 Correct 27 ms 11760 KB Output is correct
39 Correct 28 ms 11692 KB Output is correct
40 Correct 27 ms 11692 KB Output is correct
41 Correct 30 ms 11888 KB Output is correct
42 Correct 32 ms 12212 KB Output is correct
43 Correct 35 ms 11940 KB Output is correct
44 Correct 30 ms 11952 KB Output is correct
45 Correct 30 ms 12168 KB Output is correct
46 Correct 30 ms 11944 KB Output is correct
47 Correct 27 ms 11692 KB Output is correct
48 Correct 34 ms 11852 KB Output is correct
49 Correct 27 ms 11560 KB Output is correct
50 Correct 27 ms 11688 KB Output is correct
51 Correct 27 ms 11700 KB Output is correct
52 Correct 26 ms 11688 KB Output is correct
53 Correct 27 ms 11704 KB Output is correct
54 Correct 28 ms 11596 KB Output is correct
55 Correct 27 ms 11668 KB Output is correct
56 Correct 27 ms 11692 KB Output is correct
57 Correct 27 ms 11644 KB Output is correct
58 Correct 32 ms 11564 KB Output is correct
59 Correct 26 ms 11396 KB Output is correct
60 Correct 25 ms 11384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 11368 KB Output is correct
2 Correct 34 ms 11416 KB Output is correct
3 Correct 2 ms 792 KB Output is correct
4 Correct 23 ms 11084 KB Output is correct
5 Correct 31 ms 12412 KB Output is correct
6 Correct 33 ms 12408 KB Output is correct
7 Correct 27 ms 11388 KB Output is correct
8 Correct 27 ms 11392 KB Output is correct
9 Correct 32 ms 12288 KB Output is correct
10 Correct 33 ms 12408 KB Output is correct
11 Correct 35 ms 12340 KB Output is correct
12 Correct 32 ms 12424 KB Output is correct
13 Correct 31 ms 12408 KB Output is correct
14 Correct 33 ms 12332 KB Output is correct
15 Correct 31 ms 12424 KB Output is correct
16 Correct 32 ms 12812 KB Output is correct
17 Correct 34 ms 12524 KB Output is correct
18 Correct 31 ms 12556 KB Output is correct
19 Correct 31 ms 12644 KB Output is correct
20 Correct 32 ms 12632 KB Output is correct
21 Correct 31 ms 12640 KB Output is correct
22 Correct 35 ms 12592 KB Output is correct
23 Correct 27 ms 11612 KB Output is correct
24 Correct 27 ms 12020 KB Output is correct
25 Correct 27 ms 11900 KB Output is correct
26 Correct 27 ms 11872 KB Output is correct
27 Correct 30 ms 12400 KB Output is correct
28 Correct 30 ms 12152 KB Output is correct
29 Correct 30 ms 12420 KB Output is correct
30 Correct 30 ms 12656 KB Output is correct
31 Correct 27 ms 11632 KB Output is correct
32 Correct 27 ms 11644 KB Output is correct
33 Correct 27 ms 11900 KB Output is correct
34 Correct 27 ms 11880 KB Output is correct
35 Correct 28 ms 12128 KB Output is correct
36 Correct 30 ms 12096 KB Output is correct
37 Correct 30 ms 12216 KB Output is correct
38 Correct 32 ms 12144 KB Output is correct
39 Correct 30 ms 12036 KB Output is correct
40 Correct 30 ms 12168 KB Output is correct
41 Correct 30 ms 12304 KB Output is correct
42 Correct 31 ms 12396 KB Output is correct
43 Correct 30 ms 12420 KB Output is correct
44 Correct 31 ms 12372 KB Output is correct
45 Correct 28 ms 12384 KB Output is correct
46 Correct 31 ms 12380 KB Output is correct
47 Correct 27 ms 12112 KB Output is correct
48 Correct 40 ms 12080 KB Output is correct
49 Correct 27 ms 11876 KB Output is correct
50 Correct 27 ms 12072 KB Output is correct
51 Correct 27 ms 12120 KB Output is correct
52 Correct 27 ms 11900 KB Output is correct
53 Correct 27 ms 11848 KB Output is correct
54 Correct 26 ms 11856 KB Output is correct
55 Correct 27 ms 12032 KB Output is correct
56 Correct 27 ms 12112 KB Output is correct
57 Correct 31 ms 12112 KB Output is correct
58 Correct 27 ms 11896 KB Output is correct
59 Correct 27 ms 11868 KB Output is correct
60 Correct 30 ms 11804 KB Output is correct