Submission #748693

# Submission time Handle Problem Language Result Execution time Memory
748693 2023-05-26T18:14:46 Z piOOE Stray Cat (JOI20_stray) C++17
20 / 100
53 ms 16624 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    std::vector<int> X(M, -1);
    vector<vector<pair<int, int>>> adj(N);

    for (int i = 0; i < M; ++i) {
        adj[U[i]].push_back({V[i], i});
        adj[V[i]].push_back({U[i], i});
    }

    vector<int> dist(N, -1), par(N), e(N, -1), ord;
    dist[0] = 0;
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        ord.push_back(v);

        for (auto [to, i] : adj[v]) {
            if (dist[to] == -1) {
                dist[to] = dist[v] + 1;
                par[to] = v;
                e[to] = i;
                q.push(to);
            }
        }
    }

    if (A >= 3) {
        for (int i = 0; i < M; ++i) {
            if (dist[U[i]] > dist[V[i]]) {
                swap(U[i], V[i]);
            }
            X[i] = dist[U[i]] % 3;
        }
    } else {
        vector<int> code{0, 1, 1, 0, 0, 1};
        vector<int> dp(N, -1);

        for (int x : ord) {
            if (e[x] == -1 || par[x] && adj[par[x]].size() >= 3) {
                if (e[x] == -1 || X[e[x]] == 1) {
                    dp[x] = 1;
                } else {
                    dp[x] = 0;
                }
            }

            if (x && adj[x].size() > 2) {
                int c = e[x] == -1 || X[e[x]] == 1 ? 0 : 1;
                for (auto [to, i] : adj[x]) {
                    if (i != e[x]) {
                        X[i] = c;
                    }
                }
            } else {
                dp[x] = (dp[x] + 1) % size(code);

                for (auto [to, i] : adj[x]) {
                    if (i != e[x]) {
                        X[i] = code[dp[x]];
                        dp[to] = dp[x];
                    }
                }
            }
        }
    }

    assert(find(X.begin(), X.end(), -1) == X.end());

    return X;
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

namespace {
    int A, B, e = -1;
    bool ok = false;

    vector<int> adj;
    vector<int> code{0, 1, 1, 0, 0, 1};

    bool extendable(vector<int> a) {
        for (int i = 0; i < size(code); ++i) {
            bool yay = true;

            for (int k = 0; k < size(a); ++k) {
                if (a[k] != code[(i + k) % size(code)]) {
                    yay = false;
                    break;
                }
            }

            if (yay) {
                return true;
            }
        }
        
        return false;
    }
}

void Init(int A, int B) {
    ::A = A;
    ::B = B;
}

int Move(std::vector<int> yy) {
    vector<int> y = yy;
    if (e != -1) {
        y[e] += 1;
    }

    int deg = accumulate(y.begin(), y.end(), 0);

    if (A >= 3) {
        int fi = -1, se = -1, cnt = 0;

        for (int i = 0; i < A; ++i) {
            if (y[i]) {
                fi = fi == -1 ? i : fi;
                se = i;
                cnt += 1;
            }
        }

        if (fi != 0 || se != 2) {
            return e = fi;
        } else {
            return e = se;
        }
    } else {
        if (deg == 2) {
            if (ok) {
                return e = find(yy.begin(), yy.end(), 1) - yy.begin();
            }

            int a = -1, b = -1;

            for (int i = 0; i < A; ++i) {
                if (y[i]) {
                    a = a == -1 ? i : a;
                    b = i;
                }
            }

            if (e == -1) {
                adj.push_back(a);
                adj.push_back(b);
                return e = b;
            }

            int c = a ^ b ^ e;
            adj.push_back(c);

            if (adj.size() == 5) {
                ok = true;
                if (extendable(adj)) {
                    return -1;
                }
                return c;
            } else {
                return e = c;
            }
        } else {
            ok = true;
            int ans = find(y.begin(), y.end(), 1) - y.begin();
            if (ans == e) {
                return -1;
            } else {
                return e = ans;
            }
        }

        assert(false);
    }
}

Compilation message

Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:48:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   48 |             if (e[x] == -1 || par[x] && adj[par[x]].size() >= 3) {

Catherine.cpp: In function 'bool {anonymous}::extendable(std::vector<int>)':
Catherine.cpp:14:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for (int i = 0; i < size(code); ++i) {
      |                         ~~^~~~~~~~~~~~
Catherine.cpp:17:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             for (int k = 0; k < size(a); ++k) {
      |                             ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15388 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 40 ms 14716 KB Output is correct
4 Correct 51 ms 16624 KB Output is correct
5 Correct 50 ms 16396 KB Output is correct
6 Correct 36 ms 15156 KB Output is correct
7 Correct 38 ms 15172 KB Output is correct
8 Correct 44 ms 15888 KB Output is correct
9 Correct 46 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15388 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 40 ms 14716 KB Output is correct
4 Correct 51 ms 16624 KB Output is correct
5 Correct 50 ms 16396 KB Output is correct
6 Correct 36 ms 15156 KB Output is correct
7 Correct 38 ms 15172 KB Output is correct
8 Correct 44 ms 15888 KB Output is correct
9 Correct 46 ms 15948 KB Output is correct
10 Correct 33 ms 13136 KB Output is correct
11 Correct 41 ms 13204 KB Output is correct
12 Correct 35 ms 13148 KB Output is correct
13 Correct 33 ms 13332 KB Output is correct
14 Correct 33 ms 13388 KB Output is correct
15 Correct 48 ms 13840 KB Output is correct
16 Correct 51 ms 15904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12968 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 31 ms 12620 KB Output is correct
4 Correct 51 ms 14244 KB Output is correct
5 Correct 53 ms 14224 KB Output is correct
6 Correct 44 ms 12964 KB Output is correct
7 Correct 40 ms 12952 KB Output is correct
8 Correct 42 ms 13684 KB Output is correct
9 Correct 43 ms 13696 KB Output is correct
10 Correct 45 ms 13316 KB Output is correct
11 Correct 40 ms 13360 KB Output is correct
12 Correct 40 ms 13364 KB Output is correct
13 Correct 39 ms 13420 KB Output is correct
14 Correct 40 ms 13672 KB Output is correct
15 Correct 42 ms 13620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12968 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 31 ms 12620 KB Output is correct
4 Correct 51 ms 14244 KB Output is correct
5 Correct 53 ms 14224 KB Output is correct
6 Correct 44 ms 12964 KB Output is correct
7 Correct 40 ms 12952 KB Output is correct
8 Correct 42 ms 13684 KB Output is correct
9 Correct 43 ms 13696 KB Output is correct
10 Correct 45 ms 13316 KB Output is correct
11 Correct 40 ms 13360 KB Output is correct
12 Correct 40 ms 13364 KB Output is correct
13 Correct 39 ms 13420 KB Output is correct
14 Correct 40 ms 13672 KB Output is correct
15 Correct 42 ms 13620 KB Output is correct
16 Correct 31 ms 11416 KB Output is correct
17 Correct 31 ms 11448 KB Output is correct
18 Correct 31 ms 11364 KB Output is correct
19 Correct 31 ms 11260 KB Output is correct
20 Correct 37 ms 11876 KB Output is correct
21 Correct 38 ms 11736 KB Output is correct
22 Correct 41 ms 13752 KB Output is correct
23 Correct 33 ms 11512 KB Output is correct
24 Correct 33 ms 11408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 2 ms 904 KB Output is correct
4 Correct 2 ms 908 KB Output is correct
5 Correct 2 ms 896 KB Output is correct
6 Correct 2 ms 900 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 904 KB Output is correct
10 Correct 2 ms 904 KB Output is correct
11 Correct 2 ms 904 KB Output is correct
12 Correct 2 ms 896 KB Output is correct
13 Correct 2 ms 904 KB Output is correct
14 Correct 2 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 904 KB Output is correct
19 Correct 2 ms 904 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 2 ms 904 KB Output is correct
22 Correct 2 ms 896 KB Output is correct
23 Correct 2 ms 896 KB Output is correct
24 Correct 2 ms 896 KB Output is correct
25 Correct 2 ms 904 KB Output is correct
26 Correct 2 ms 900 KB Output is correct
27 Correct 2 ms 896 KB Output is correct
28 Correct 2 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 11088 KB Output is correct
2 Correct 35 ms 11496 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 28 ms 11124 KB Output is correct
5 Correct 43 ms 12160 KB Output is correct
6 Correct 43 ms 12180 KB Output is correct
7 Correct 37 ms 11340 KB Output is correct
8 Correct 34 ms 11388 KB Output is correct
9 Correct 44 ms 12148 KB Output is correct
10 Correct 40 ms 12232 KB Output is correct
11 Correct 39 ms 12256 KB Output is correct
12 Correct 41 ms 12276 KB Output is correct
13 Correct 45 ms 12164 KB Output is correct
14 Correct 40 ms 12252 KB Output is correct
15 Correct 40 ms 12220 KB Output is correct
16 Correct 41 ms 12216 KB Output is correct
17 Correct 41 ms 11948 KB Output is correct
18 Correct 43 ms 11960 KB Output is correct
19 Correct 37 ms 11924 KB Output is correct
20 Correct 37 ms 11956 KB Output is correct
21 Correct 40 ms 11928 KB Output is correct
22 Correct 37 ms 12036 KB Output is correct
23 Correct 31 ms 11120 KB Output is correct
24 Correct 32 ms 11112 KB Output is correct
25 Correct 36 ms 11320 KB Output is correct
26 Correct 32 ms 11248 KB Output is correct
27 Correct 51 ms 11724 KB Output is correct
28 Correct 41 ms 11672 KB Output is correct
29 Correct 36 ms 11624 KB Output is correct
30 Correct 37 ms 11736 KB Output is correct
31 Correct 33 ms 11216 KB Output is correct
32 Correct 33 ms 11100 KB Output is correct
33 Correct 39 ms 11200 KB Output is correct
34 Correct 32 ms 11216 KB Output is correct
35 Correct 37 ms 11548 KB Output is correct
36 Correct 36 ms 11648 KB Output is correct
37 Correct 37 ms 11540 KB Output is correct
38 Correct 37 ms 11496 KB Output is correct
39 Correct 39 ms 11600 KB Output is correct
40 Correct 40 ms 11644 KB Output is correct
41 Correct 41 ms 11804 KB Output is correct
42 Correct 38 ms 11880 KB Output is correct
43 Correct 40 ms 11864 KB Output is correct
44 Correct 41 ms 12052 KB Output is correct
45 Correct 40 ms 11940 KB Output is correct
46 Correct 39 ms 11924 KB Output is correct
47 Correct 38 ms 11592 KB Output is correct
48 Correct 37 ms 11544 KB Output is correct
49 Correct 45 ms 11336 KB Output is correct
50 Correct 37 ms 11540 KB Output is correct
51 Correct 33 ms 11348 KB Output is correct
52 Correct 33 ms 11392 KB Output is correct
53 Correct 33 ms 11228 KB Output is correct
54 Correct 32 ms 11456 KB Output is correct
55 Correct 35 ms 11340 KB Output is correct
56 Correct 34 ms 11356 KB Output is correct
57 Correct 34 ms 11184 KB Output is correct
58 Correct 35 ms 11244 KB Output is correct
59 Incorrect 31 ms 11496 KB Wrong Answer [3]
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11100 KB Output is correct
2 Correct 34 ms 11312 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 27 ms 11100 KB Output is correct
5 Correct 41 ms 12240 KB Output is correct
6 Correct 42 ms 12212 KB Output is correct
7 Correct 33 ms 11376 KB Output is correct
8 Correct 34 ms 11348 KB Output is correct
9 Correct 44 ms 12216 KB Output is correct
10 Correct 44 ms 12236 KB Output is correct
11 Correct 40 ms 12316 KB Output is correct
12 Correct 43 ms 12232 KB Output is correct
13 Correct 44 ms 12332 KB Output is correct
14 Correct 48 ms 12172 KB Output is correct
15 Correct 43 ms 12256 KB Output is correct
16 Correct 41 ms 12308 KB Output is correct
17 Correct 37 ms 12008 KB Output is correct
18 Correct 47 ms 11980 KB Output is correct
19 Correct 48 ms 12004 KB Output is correct
20 Correct 38 ms 12004 KB Output is correct
21 Correct 37 ms 11984 KB Output is correct
22 Correct 41 ms 11844 KB Output is correct
23 Correct 34 ms 11188 KB Output is correct
24 Correct 33 ms 11188 KB Output is correct
25 Correct 37 ms 11264 KB Output is correct
26 Correct 36 ms 11228 KB Output is correct
27 Correct 39 ms 11620 KB Output is correct
28 Correct 40 ms 11548 KB Output is correct
29 Correct 39 ms 11736 KB Output is correct
30 Correct 40 ms 11700 KB Output is correct
31 Correct 33 ms 11100 KB Output is correct
32 Correct 36 ms 11520 KB Output is correct
33 Correct 36 ms 11820 KB Output is correct
34 Correct 33 ms 11832 KB Output is correct
35 Correct 36 ms 12016 KB Output is correct
36 Correct 36 ms 11984 KB Output is correct
37 Correct 37 ms 12044 KB Output is correct
38 Correct 37 ms 12032 KB Output is correct
39 Correct 39 ms 12088 KB Output is correct
40 Correct 37 ms 12068 KB Output is correct
41 Correct 37 ms 12328 KB Output is correct
42 Correct 38 ms 12344 KB Output is correct
43 Correct 40 ms 12320 KB Output is correct
44 Correct 48 ms 12404 KB Output is correct
45 Correct 38 ms 12496 KB Output is correct
46 Correct 39 ms 12276 KB Output is correct
47 Correct 39 ms 11900 KB Output is correct
48 Correct 35 ms 11892 KB Output is correct
49 Correct 37 ms 11976 KB Output is correct
50 Correct 40 ms 12028 KB Output is correct
51 Correct 37 ms 11844 KB Output is correct
52 Correct 35 ms 11732 KB Output is correct
53 Correct 42 ms 11784 KB Output is correct
54 Correct 36 ms 11796 KB Output is correct
55 Correct 33 ms 11828 KB Output is correct
56 Correct 33 ms 11672 KB Output is correct
57 Correct 33 ms 11556 KB Output is correct
58 Correct 34 ms 11652 KB Output is correct
59 Incorrect 30 ms 11832 KB Wrong Answer [3]
60 Halted 0 ms 0 KB -