답안 #939334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939334 2024-03-06T09:24:28 Z Pring 길고양이 (JOI20_stray) C++17
100 / 100
40 ms 17080 KB
#include <bits/stdc++.h>
#include "Anthony.h"
using namespace std;

const string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

namespace {
    const int MXN = 20005;
    int n, m, A, B;
    vector<int> eu, ev;
    vector<int> eid[MXN];
    int deg[MXN];

    namespace NSA {
        int d[MXN];
        vector<int> tag;

        void BFS(int sr) {
            fill(d, d + n, -1);
            queue<pii> q;
            q.push(mp(0, sr));
            while (q.size()) {
                auto [dep, id] = q.front();
                q.pop();
                if (d[id] != -1) continue;
                d[id] = dep;
                for (auto &e : eid[id]) {
                    int i = eu[e] ^ ev[e] ^ id;
                    if (d[i] != -1) continue;
                    q.push(mp(dep + 1, i));
                }
            }
        }

        vector<int> Mark() {
            BFS(0);
            tag.resize(m);
            FOR(i, 0, m) {
                if (d[eu[i]] == d[ev[i]]) tag[i] = d[eu[i]] % 3;
                else tag[i] = min(d[eu[i]], d[ev[i]]) % 3;
            }
            return tag;
        }
    }

    namespace NSB {
        const int mans[6] = {1, 1, 0, 0, 1, 0};
        const int mnxt[6] = {2, 2, 0, 0, 2, 0};
        vector<int> tag;

        void BFS(int sr) {
            queue<pii> q;
            for (auto &e : eid[sr]) q.push(mp(e, eu[e] ^ ev[e] ^ sr));
            while (q.size()) {
                auto [ep, id] = q.front();
                q.pop();
                int nxt = (deg[id] == 2 ? (tag[ep] + 1) % 6 : mnxt[tag[ep]]);
                for (auto &e : eid[id]) {
                    if (e == ep) continue;
                    int i = eu[e] ^ ev[e] ^ id;
                    tag[e] = nxt;
                    q.push(mp(e, i));
                }
            }
        }

        vector<int> Mark() {
            tag.resize(m);
            BFS(0);
            FOR(i, 0, m) tag[i] = mans[tag[i]];
            return tag;
        }
    }
}

vector<int> Mark(int _n, int _m, int _a, int _b, vector<int> _eu, vector<int> _ev) {
    n = _n;
    m = _m;
    A = _a;
    B = _b;
    eu = _eu;
    ev = _ev;
    FOR(i, 0, m) {
        eid[eu[i]].push_back(i);
        eid[ev[i]].push_back(i);
        deg[eu[i]]++;
        deg[ev[i]]++;
    }
    return (A >= 3 ? NSA::Mark() : NSB::Mark());
}
#include <bits/stdc++.h>
#include "Catherine.h"
using namespace std;

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

namespace {
    int A, B;

    namespace NSA {
        int Move(vector<int> &y) {
            int a = y[0], b = y[1], c = y[2];
            int cnt = (a != 0) + (b != 0) + (c != 0);
            if (cnt == 1) return (a ? 0 : (b ? 1 : 2));
            return (a == 0 ? 1 : (b == 0 ? 2 : 0));
        }
    }

    namespace NSB {
        bool confused;
        int lst;
        string go;

        // 110010

        bool far() {
            string t = "110010110010";
            FOR(i, 0, 6) if (t.substr(i, 5) == go) return true;
            return false;
        }

        int Move(vector<int> &y) {
            int deg = y[0] + y[1];
            if (lst == -1) {
                if (deg == 1) {
                    confused = false;
                    return (lst = (y[0] ? 0 : 1));
                }
                if (deg > 2) {
                    confused = false;
                    return (lst = (y[0] == 1 ? 0 : 1));
                }
                if (y[0] == 1) {
                    go = "01";
                    return (lst = 1);
                }
                if (y[0]) {
                    go = "00";
                    return (lst = 0);
                }
                go = "11";
                return (lst = 1);
            }
            if (confused) {
                if (deg == 0) {
                    confused = false;
                    return -1;
                }
                if (deg > 1) {
                    if (y[0] && y[1]) {
                        confused = false;
                        return (lst = (lst ^ 1));
                    }
                    confused = false;
                    return -1;
                }
                go.push_back(y[0] ? '0' : '1');
                if (go.size() == 5) {
                    confused = false;
                    if (far()) return -1;
                }
                return (lst = (y[0] ? 0 : 1));
            }
            if (deg > 1) return (lst = (lst ^ 1));
            return (lst = (y[0] ? 0 : 1));
        }
    }
}

void Init(int _a, int _b) {
    A = _a;
    B = _b;
    NSB::confused = true;
    NSB::lst = -1;
}

int Move(vector<int> y) {
    return (A >= 3 ? NSA::Move(y) : NSB::Move(y));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 15996 KB Output is correct
2 Correct 1 ms 1296 KB Output is correct
3 Correct 24 ms 15188 KB Output is correct
4 Correct 33 ms 16956 KB Output is correct
5 Correct 37 ms 17080 KB Output is correct
6 Correct 27 ms 15744 KB Output is correct
7 Correct 30 ms 15640 KB Output is correct
8 Correct 32 ms 16504 KB Output is correct
9 Correct 39 ms 16428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 15996 KB Output is correct
2 Correct 1 ms 1296 KB Output is correct
3 Correct 24 ms 15188 KB Output is correct
4 Correct 33 ms 16956 KB Output is correct
5 Correct 37 ms 17080 KB Output is correct
6 Correct 27 ms 15744 KB Output is correct
7 Correct 30 ms 15640 KB Output is correct
8 Correct 32 ms 16504 KB Output is correct
9 Correct 39 ms 16428 KB Output is correct
10 Correct 26 ms 13676 KB Output is correct
11 Correct 26 ms 13680 KB Output is correct
12 Correct 26 ms 13456 KB Output is correct
13 Correct 27 ms 13356 KB Output is correct
14 Correct 26 ms 13940 KB Output is correct
15 Correct 32 ms 14084 KB Output is correct
16 Correct 30 ms 16492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13396 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 23 ms 12912 KB Output is correct
4 Correct 32 ms 14964 KB Output is correct
5 Correct 32 ms 14980 KB Output is correct
6 Correct 26 ms 13428 KB Output is correct
7 Correct 26 ms 13360 KB Output is correct
8 Correct 30 ms 14164 KB Output is correct
9 Correct 31 ms 14028 KB Output is correct
10 Correct 30 ms 13820 KB Output is correct
11 Correct 28 ms 13940 KB Output is correct
12 Correct 28 ms 13972 KB Output is correct
13 Correct 33 ms 13944 KB Output is correct
14 Correct 34 ms 14188 KB Output is correct
15 Correct 30 ms 14200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13396 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 23 ms 12912 KB Output is correct
4 Correct 32 ms 14964 KB Output is correct
5 Correct 32 ms 14980 KB Output is correct
6 Correct 26 ms 13428 KB Output is correct
7 Correct 26 ms 13360 KB Output is correct
8 Correct 30 ms 14164 KB Output is correct
9 Correct 31 ms 14028 KB Output is correct
10 Correct 30 ms 13820 KB Output is correct
11 Correct 28 ms 13940 KB Output is correct
12 Correct 28 ms 13972 KB Output is correct
13 Correct 33 ms 13944 KB Output is correct
14 Correct 34 ms 14188 KB Output is correct
15 Correct 30 ms 14200 KB Output is correct
16 Correct 23 ms 11892 KB Output is correct
17 Correct 24 ms 11892 KB Output is correct
18 Correct 25 ms 11632 KB Output is correct
19 Correct 24 ms 11640 KB Output is correct
20 Correct 26 ms 12412 KB Output is correct
21 Correct 26 ms 12132 KB Output is correct
22 Correct 28 ms 14452 KB Output is correct
23 Correct 25 ms 11904 KB Output is correct
24 Correct 26 ms 11944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1560 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 2 ms 1568 KB Output is correct
4 Correct 2 ms 1560 KB Output is correct
5 Correct 2 ms 1552 KB Output is correct
6 Correct 2 ms 1560 KB Output is correct
7 Correct 2 ms 1560 KB Output is correct
8 Correct 2 ms 1564 KB Output is correct
9 Correct 2 ms 1564 KB Output is correct
10 Correct 2 ms 1568 KB Output is correct
11 Correct 1 ms 1564 KB Output is correct
12 Correct 1 ms 1560 KB Output is correct
13 Correct 2 ms 1552 KB Output is correct
14 Correct 1 ms 1564 KB Output is correct
15 Correct 2 ms 1568 KB Output is correct
16 Correct 1 ms 1552 KB Output is correct
17 Correct 2 ms 1560 KB Output is correct
18 Correct 2 ms 1568 KB Output is correct
19 Correct 2 ms 1564 KB Output is correct
20 Correct 2 ms 1560 KB Output is correct
21 Correct 1 ms 1560 KB Output is correct
22 Correct 2 ms 1560 KB Output is correct
23 Correct 2 ms 1568 KB Output is correct
24 Correct 2 ms 1568 KB Output is correct
25 Correct 2 ms 1568 KB Output is correct
26 Correct 2 ms 1568 KB Output is correct
27 Correct 1 ms 1552 KB Output is correct
28 Correct 2 ms 1568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11380 KB Output is correct
2 Correct 26 ms 11648 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 22 ms 11360 KB Output is correct
5 Correct 36 ms 12648 KB Output is correct
6 Correct 30 ms 12656 KB Output is correct
7 Correct 27 ms 11640 KB Output is correct
8 Correct 26 ms 11888 KB Output is correct
9 Correct 31 ms 12676 KB Output is correct
10 Correct 31 ms 12676 KB Output is correct
11 Correct 28 ms 12660 KB Output is correct
12 Correct 30 ms 12632 KB Output is correct
13 Correct 28 ms 12664 KB Output is correct
14 Correct 28 ms 12632 KB Output is correct
15 Correct 30 ms 12668 KB Output is correct
16 Correct 30 ms 12640 KB Output is correct
17 Correct 28 ms 12408 KB Output is correct
18 Correct 27 ms 12404 KB Output is correct
19 Correct 28 ms 12412 KB Output is correct
20 Correct 27 ms 12408 KB Output is correct
21 Correct 27 ms 12420 KB Output is correct
22 Correct 27 ms 12392 KB Output is correct
23 Correct 25 ms 11120 KB Output is correct
24 Correct 25 ms 11384 KB Output is correct
25 Correct 25 ms 11384 KB Output is correct
26 Correct 25 ms 11380 KB Output is correct
27 Correct 28 ms 11836 KB Output is correct
28 Correct 26 ms 11896 KB Output is correct
29 Correct 27 ms 11888 KB Output is correct
30 Correct 26 ms 11900 KB Output is correct
31 Correct 25 ms 11124 KB Output is correct
32 Correct 24 ms 11124 KB Output is correct
33 Correct 26 ms 11636 KB Output is correct
34 Correct 25 ms 11640 KB Output is correct
35 Correct 34 ms 11676 KB Output is correct
36 Correct 26 ms 11764 KB Output is correct
37 Correct 26 ms 11732 KB Output is correct
38 Correct 26 ms 11608 KB Output is correct
39 Correct 26 ms 12008 KB Output is correct
40 Correct 26 ms 11644 KB Output is correct
41 Correct 27 ms 12080 KB Output is correct
42 Correct 28 ms 12148 KB Output is correct
43 Correct 31 ms 12100 KB Output is correct
44 Correct 28 ms 12116 KB Output is correct
45 Correct 27 ms 12112 KB Output is correct
46 Correct 27 ms 12084 KB Output is correct
47 Correct 26 ms 11644 KB Output is correct
48 Correct 26 ms 11636 KB Output is correct
49 Correct 32 ms 11748 KB Output is correct
50 Correct 26 ms 11608 KB Output is correct
51 Correct 24 ms 11128 KB Output is correct
52 Correct 25 ms 11132 KB Output is correct
53 Correct 25 ms 11388 KB Output is correct
54 Correct 24 ms 11396 KB Output is correct
55 Correct 24 ms 11380 KB Output is correct
56 Correct 26 ms 11052 KB Output is correct
57 Correct 25 ms 11432 KB Output is correct
58 Correct 25 ms 11420 KB Output is correct
59 Correct 25 ms 11648 KB Output is correct
60 Correct 25 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11396 KB Output is correct
2 Correct 26 ms 11600 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 27 ms 11964 KB Output is correct
5 Correct 31 ms 13224 KB Output is correct
6 Correct 30 ms 13140 KB Output is correct
7 Correct 28 ms 12088 KB Output is correct
8 Correct 29 ms 12084 KB Output is correct
9 Correct 32 ms 13140 KB Output is correct
10 Correct 30 ms 13104 KB Output is correct
11 Correct 30 ms 13136 KB Output is correct
12 Correct 32 ms 13228 KB Output is correct
13 Correct 30 ms 13144 KB Output is correct
14 Correct 30 ms 13140 KB Output is correct
15 Correct 34 ms 13176 KB Output is correct
16 Correct 28 ms 13152 KB Output is correct
17 Correct 27 ms 12872 KB Output is correct
18 Correct 28 ms 12872 KB Output is correct
19 Correct 28 ms 12628 KB Output is correct
20 Correct 28 ms 12872 KB Output is correct
21 Correct 27 ms 12848 KB Output is correct
22 Correct 28 ms 12956 KB Output is correct
23 Correct 24 ms 11576 KB Output is correct
24 Correct 25 ms 11712 KB Output is correct
25 Correct 25 ms 11980 KB Output is correct
26 Correct 25 ms 11856 KB Output is correct
27 Correct 26 ms 12192 KB Output is correct
28 Correct 26 ms 12396 KB Output is correct
29 Correct 26 ms 12296 KB Output is correct
30 Correct 27 ms 12360 KB Output is correct
31 Correct 24 ms 11584 KB Output is correct
32 Correct 25 ms 11556 KB Output is correct
33 Correct 25 ms 12048 KB Output is correct
34 Correct 25 ms 11860 KB Output is correct
35 Correct 27 ms 12184 KB Output is correct
36 Correct 26 ms 12116 KB Output is correct
37 Correct 28 ms 12112 KB Output is correct
38 Correct 26 ms 12452 KB Output is correct
39 Correct 26 ms 12532 KB Output is correct
40 Correct 27 ms 12044 KB Output is correct
41 Correct 34 ms 12456 KB Output is correct
42 Correct 30 ms 12628 KB Output is correct
43 Correct 30 ms 12744 KB Output is correct
44 Correct 37 ms 12608 KB Output is correct
45 Correct 30 ms 12584 KB Output is correct
46 Correct 30 ms 12544 KB Output is correct
47 Correct 32 ms 12404 KB Output is correct
48 Correct 26 ms 12072 KB Output is correct
49 Correct 40 ms 12048 KB Output is correct
50 Correct 34 ms 12336 KB Output is correct
51 Correct 31 ms 11508 KB Output is correct
52 Correct 30 ms 11804 KB Output is correct
53 Correct 28 ms 11768 KB Output is correct
54 Correct 27 ms 11696 KB Output is correct
55 Correct 25 ms 11600 KB Output is correct
56 Correct 25 ms 11724 KB Output is correct
57 Correct 32 ms 11948 KB Output is correct
58 Correct 27 ms 11856 KB Output is correct
59 Correct 26 ms 11928 KB Output is correct
60 Correct 34 ms 12080 KB Output is correct