Submission #748709

# Submission time Handle Problem Language Result Execution time Memory
748709 2023-05-26T18:37:30 Z piOOE Stray Cat (JOI20_stray) C++17
100 / 100
61 ms 16440 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, 0, 0, 1, 1};
        vector<int> dp(N, -1);

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

            if (dp[x] >= 0) {
                X[e[x]] = code[dp[x]];
            }
        }
    }

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

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

using namespace std;


namespace {
    string code = "010011", adj;
    int A, B, e = -1;
    bool known = false;
}

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

int Move(std::vector<int> y) {
    vector<int> yy = y;

    if (e != -1) {
        yy[e] += 1;
    }

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

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

        for (int i = 0; i < A; ++i) {
            if (yy[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 (known) {
                return e = find(y.begin(), y.end(), 1) - y.begin();
            }

            for (int i = 0; i < A; ++i) {
                adj += string(y[i], char('0' + i));
            }

            if (adj.size() == 5) {
                known = true;
                string s = code + code;

                for (int i = 0; i < 6; ++i) {
                    if (adj == s.substr(i, 5)) {
                        return -1;
                    }
                }

                return e = find(y.begin(), y.end(), 1) - y.begin();
            } else {
                return e = adj.back() - '0';
            }
        } else {
            known = true;
            int u = find(yy.begin(), yy.end(), 1) - yy.begin();
            return u == e ? -1 : e = u;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15356 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 31 ms 14824 KB Output is correct
4 Correct 45 ms 16432 KB Output is correct
5 Correct 45 ms 16440 KB Output is correct
6 Correct 35 ms 15272 KB Output is correct
7 Correct 49 ms 15096 KB Output is correct
8 Correct 61 ms 15944 KB Output is correct
9 Correct 51 ms 15900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15356 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 31 ms 14824 KB Output is correct
4 Correct 45 ms 16432 KB Output is correct
5 Correct 45 ms 16440 KB Output is correct
6 Correct 35 ms 15272 KB Output is correct
7 Correct 49 ms 15096 KB Output is correct
8 Correct 61 ms 15944 KB Output is correct
9 Correct 51 ms 15900 KB Output is correct
10 Correct 44 ms 13152 KB Output is correct
11 Correct 35 ms 13192 KB Output is correct
12 Correct 32 ms 13292 KB Output is correct
13 Correct 32 ms 13196 KB Output is correct
14 Correct 33 ms 13528 KB Output is correct
15 Correct 41 ms 13844 KB Output is correct
16 Correct 43 ms 15996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12960 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 28 ms 12604 KB Output is correct
4 Correct 55 ms 14300 KB Output is correct
5 Correct 48 ms 14296 KB Output is correct
6 Correct 34 ms 13052 KB Output is correct
7 Correct 41 ms 12892 KB Output is correct
8 Correct 44 ms 13676 KB Output is correct
9 Correct 50 ms 13620 KB Output is correct
10 Correct 41 ms 13432 KB Output is correct
11 Correct 41 ms 13444 KB Output is correct
12 Correct 46 ms 13404 KB Output is correct
13 Correct 40 ms 13336 KB Output is correct
14 Correct 41 ms 13584 KB Output is correct
15 Correct 42 ms 13704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 12960 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 28 ms 12604 KB Output is correct
4 Correct 55 ms 14300 KB Output is correct
5 Correct 48 ms 14296 KB Output is correct
6 Correct 34 ms 13052 KB Output is correct
7 Correct 41 ms 12892 KB Output is correct
8 Correct 44 ms 13676 KB Output is correct
9 Correct 50 ms 13620 KB Output is correct
10 Correct 41 ms 13432 KB Output is correct
11 Correct 41 ms 13444 KB Output is correct
12 Correct 46 ms 13404 KB Output is correct
13 Correct 40 ms 13336 KB Output is correct
14 Correct 41 ms 13584 KB Output is correct
15 Correct 42 ms 13704 KB Output is correct
16 Correct 31 ms 11284 KB Output is correct
17 Correct 32 ms 11368 KB Output is correct
18 Correct 32 ms 11304 KB Output is correct
19 Correct 32 ms 11304 KB Output is correct
20 Correct 37 ms 11960 KB Output is correct
21 Correct 32 ms 11852 KB Output is correct
22 Correct 39 ms 13672 KB Output is correct
23 Correct 30 ms 11392 KB Output is correct
24 Correct 38 ms 11360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 2 ms 896 KB Output is correct
5 Correct 2 ms 904 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 2 ms 908 KB Output is correct
8 Correct 2 ms 904 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 904 KB Output is correct
11 Correct 2 ms 896 KB Output is correct
12 Correct 2 ms 904 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 2 ms 900 KB Output is correct
15 Correct 2 ms 900 KB Output is correct
16 Correct 2 ms 908 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 904 KB Output is correct
21 Correct 2 ms 896 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 896 KB Output is correct
26 Correct 2 ms 896 KB Output is correct
27 Correct 2 ms 892 KB Output is correct
28 Correct 2 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 11372 KB Output is correct
2 Correct 34 ms 11648 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 26 ms 11116 KB Output is correct
5 Correct 39 ms 12220 KB Output is correct
6 Correct 40 ms 12212 KB Output is correct
7 Correct 32 ms 11404 KB Output is correct
8 Correct 32 ms 11392 KB Output is correct
9 Correct 50 ms 12228 KB Output is correct
10 Correct 43 ms 12220 KB Output is correct
11 Correct 41 ms 12376 KB Output is correct
12 Correct 41 ms 12204 KB Output is correct
13 Correct 38 ms 12272 KB Output is correct
14 Correct 42 ms 12184 KB Output is correct
15 Correct 43 ms 12252 KB Output is correct
16 Correct 40 ms 12268 KB Output is correct
17 Correct 39 ms 11984 KB Output is correct
18 Correct 38 ms 11988 KB Output is correct
19 Correct 38 ms 11920 KB Output is correct
20 Correct 38 ms 12024 KB Output is correct
21 Correct 36 ms 12060 KB Output is correct
22 Correct 40 ms 11996 KB Output is correct
23 Correct 31 ms 11248 KB Output is correct
24 Correct 31 ms 11316 KB Output is correct
25 Correct 34 ms 11356 KB Output is correct
26 Correct 44 ms 11276 KB Output is correct
27 Correct 37 ms 11684 KB Output is correct
28 Correct 40 ms 11684 KB Output is correct
29 Correct 46 ms 11880 KB Output is correct
30 Correct 38 ms 11708 KB Output is correct
31 Correct 33 ms 11192 KB Output is correct
32 Correct 33 ms 11256 KB Output is correct
33 Correct 33 ms 11276 KB Output is correct
34 Correct 34 ms 11344 KB Output is correct
35 Correct 37 ms 11660 KB Output is correct
36 Correct 42 ms 11616 KB Output is correct
37 Correct 39 ms 11752 KB Output is correct
38 Correct 37 ms 11680 KB Output is correct
39 Correct 42 ms 11664 KB Output is correct
40 Correct 43 ms 11696 KB Output is correct
41 Correct 45 ms 11876 KB Output is correct
42 Correct 41 ms 11992 KB Output is correct
43 Correct 38 ms 11956 KB Output is correct
44 Correct 37 ms 11896 KB Output is correct
45 Correct 45 ms 11980 KB Output is correct
46 Correct 37 ms 11936 KB Output is correct
47 Correct 38 ms 11552 KB Output is correct
48 Correct 34 ms 11624 KB Output is correct
49 Correct 36 ms 11496 KB Output is correct
50 Correct 35 ms 11616 KB Output is correct
51 Correct 33 ms 11444 KB Output is correct
52 Correct 33 ms 11368 KB Output is correct
53 Correct 33 ms 11484 KB Output is correct
54 Correct 32 ms 11520 KB Output is correct
55 Correct 34 ms 11476 KB Output is correct
56 Correct 34 ms 11504 KB Output is correct
57 Correct 34 ms 11368 KB Output is correct
58 Correct 33 ms 11284 KB Output is correct
59 Correct 33 ms 11356 KB Output is correct
60 Correct 32 ms 11376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 11036 KB Output is correct
2 Correct 37 ms 11572 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 26 ms 11116 KB Output is correct
5 Correct 40 ms 12292 KB Output is correct
6 Correct 43 ms 12212 KB Output is correct
7 Correct 34 ms 11380 KB Output is correct
8 Correct 34 ms 11384 KB Output is correct
9 Correct 48 ms 12332 KB Output is correct
10 Correct 43 ms 12180 KB Output is correct
11 Correct 40 ms 12344 KB Output is correct
12 Correct 44 ms 12324 KB Output is correct
13 Correct 41 ms 12260 KB Output is correct
14 Correct 40 ms 12180 KB Output is correct
15 Correct 40 ms 12208 KB Output is correct
16 Correct 40 ms 12240 KB Output is correct
17 Correct 38 ms 12044 KB Output is correct
18 Correct 38 ms 12044 KB Output is correct
19 Correct 38 ms 11924 KB Output is correct
20 Correct 37 ms 11924 KB Output is correct
21 Correct 38 ms 11996 KB Output is correct
22 Correct 37 ms 12016 KB Output is correct
23 Correct 34 ms 11220 KB Output is correct
24 Correct 32 ms 11336 KB Output is correct
25 Correct 36 ms 11300 KB Output is correct
26 Correct 31 ms 11312 KB Output is correct
27 Correct 37 ms 11668 KB Output is correct
28 Correct 44 ms 11788 KB Output is correct
29 Correct 37 ms 11784 KB Output is correct
30 Correct 40 ms 11716 KB Output is correct
31 Correct 35 ms 11228 KB Output is correct
32 Correct 33 ms 11304 KB Output is correct
33 Correct 34 ms 11312 KB Output is correct
34 Correct 36 ms 11364 KB Output is correct
35 Correct 41 ms 11628 KB Output is correct
36 Correct 39 ms 11736 KB Output is correct
37 Correct 37 ms 11656 KB Output is correct
38 Correct 40 ms 11668 KB Output is correct
39 Correct 46 ms 11696 KB Output is correct
40 Correct 37 ms 11764 KB Output is correct
41 Correct 40 ms 12084 KB Output is correct
42 Correct 37 ms 12004 KB Output is correct
43 Correct 37 ms 11984 KB Output is correct
44 Correct 40 ms 11984 KB Output is correct
45 Correct 37 ms 12008 KB Output is correct
46 Correct 37 ms 11996 KB Output is correct
47 Correct 35 ms 11632 KB Output is correct
48 Correct 39 ms 11568 KB Output is correct
49 Correct 33 ms 11496 KB Output is correct
50 Correct 35 ms 11624 KB Output is correct
51 Correct 34 ms 11464 KB Output is correct
52 Correct 34 ms 11620 KB Output is correct
53 Correct 33 ms 11500 KB Output is correct
54 Correct 36 ms 11488 KB Output is correct
55 Correct 32 ms 11488 KB Output is correct
56 Correct 34 ms 11432 KB Output is correct
57 Correct 32 ms 11416 KB Output is correct
58 Correct 32 ms 11372 KB Output is correct
59 Correct 32 ms 11344 KB Output is correct
60 Correct 33 ms 11324 KB Output is correct