답안 #251883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251883 2020-07-22T17:50:50 Z imeimi2000 길고양이 (JOI20_stray) C++17
100 / 100
81 ms 16876 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

static vector<int> edge[20000];
static int par[20000], pc[20000], ord[20000];
void dfs(int x, int p) {
    par[x] = p;
    ord[x] = -1;
    if (!x) {
        for (int i : edge[x]) pc[i] = 0, dfs(i, x);
    }
    else if (int(edge[x].size()) != 2) {
        for (int i : edge[x]) {
            if (i == p) continue;
            pc[i] = pc[x] ^ 1;
            dfs(i, x);
        }
    }
    else {
        ord[x] = ord[p] != -1 ? (ord[p] + 1) % 6 : (pc[x] ? 2 : 1);
        for (int i : edge[x]) {
            if (i == p) continue;
            pc[i] = "010011"[ord[x]] - '0';
            dfs(i, x);
        }
    }
}

vector<int> Mark(int n, int m, int A, int B, vector<int> U, vector<int> V) {
    for (int i = 0; i < m; ++i) {
        edge[U[i]].push_back(V[i]);
        edge[V[i]].push_back(U[i]);
    }
    if (A > 2) {
        vector<int> dist(n, -1);
        queue<int> q;
        q.push(0);
        dist[0] = 0;
        while (!q.empty()) {
            int x = q.front(); q.pop();
            for (int i : edge[x]) {
                if (dist[i] != -1) continue;
                q.push(i);
                dist[i] = dist[x] + 1;
            }
        }
        vector<int> ret(m);
        for (int i = 0; i < m; ++i) {
            int u = U[i], v = V[i];
            if (dist[u] > dist[v]) swap(u, v);
            ret[i] = dist[u] % 3;
        }
        return ret;
    }
    dfs(0, -1);
    vector<int> ret(m);
    for (int i = 0; i < m; ++i) {
        int u = U[i], v = V[i];
        if (u == par[v]) swap(u, v);
        ret[i] = pc[u];
    }
    return ret;
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

static int A, B, pr;
static vector<int> path;

void Init(int a, int b) {
    A = a, B = b;
    pr = -1;
    path.clear();
}

int Move(vector<int> cnt) {
    if (A > 2) {
        int sum = 0;
        for (int i : cnt) sum += i > 0;
        if (sum == 1) {
            for (int i = 0; ; ++i) if (cnt[i]) return i;
        }
        else if (sum == 2) {
            for (int i = 0; ; ++i) if (!cnt[i]) return (i + 1) % 3;
        }
        else exit(1);
    }
    int deg = cnt[0] + cnt[1] + (pr != -1);
    if (deg != 2) path.resize(6);
    if (int(path.size()) > 5) {
        if (deg != 2 && pr != -1) ++cnt[pr];
        for (int i = 0; i < 2; ++i) {
            if (cnt[i] == 1) {
                if (deg == 2 || pr != i) return pr = i;
                return -1;
            }
        }
        exit(2);
    }
    while (cnt[0]--) path.push_back(0);
    while (cnt[1]--) path.push_back(1);
    if (int(path.size()) == 5) {
        path.push_back(path.back());
        for (int i = 0; i < 6; ++i) {
            bool dif = 0;
            for (int j = 0; j < 5; ++j) {
                if (path[j] != "010011"[(i + j) % 6] - '0') dif = 1;
            }
            if (!dif) return -1;
        }
    }
    return pr = path.back();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 15476 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 39 ms 14840 KB Output is correct
4 Correct 57 ms 16876 KB Output is correct
5 Correct 57 ms 16636 KB Output is correct
6 Correct 45 ms 15452 KB Output is correct
7 Correct 49 ms 15356 KB Output is correct
8 Correct 54 ms 16244 KB Output is correct
9 Correct 62 ms 16124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 15476 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 39 ms 14840 KB Output is correct
4 Correct 57 ms 16876 KB Output is correct
5 Correct 57 ms 16636 KB Output is correct
6 Correct 45 ms 15452 KB Output is correct
7 Correct 49 ms 15356 KB Output is correct
8 Correct 54 ms 16244 KB Output is correct
9 Correct 62 ms 16124 KB Output is correct
10 Correct 45 ms 13476 KB Output is correct
11 Correct 44 ms 13304 KB Output is correct
12 Correct 45 ms 13452 KB Output is correct
13 Correct 51 ms 13492 KB Output is correct
14 Correct 52 ms 13776 KB Output is correct
15 Correct 61 ms 14064 KB Output is correct
16 Correct 56 ms 16368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 13284 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 36 ms 12668 KB Output is correct
4 Correct 68 ms 14708 KB Output is correct
5 Correct 58 ms 14696 KB Output is correct
6 Correct 43 ms 13044 KB Output is correct
7 Correct 43 ms 13044 KB Output is correct
8 Correct 53 ms 14068 KB Output is correct
9 Correct 50 ms 14064 KB Output is correct
10 Correct 50 ms 13796 KB Output is correct
11 Correct 53 ms 13600 KB Output is correct
12 Correct 66 ms 13668 KB Output is correct
13 Correct 50 ms 13688 KB Output is correct
14 Correct 50 ms 14060 KB Output is correct
15 Correct 51 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 13284 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 36 ms 12668 KB Output is correct
4 Correct 68 ms 14708 KB Output is correct
5 Correct 58 ms 14696 KB Output is correct
6 Correct 43 ms 13044 KB Output is correct
7 Correct 43 ms 13044 KB Output is correct
8 Correct 53 ms 14068 KB Output is correct
9 Correct 50 ms 14064 KB Output is correct
10 Correct 50 ms 13796 KB Output is correct
11 Correct 53 ms 13600 KB Output is correct
12 Correct 66 ms 13668 KB Output is correct
13 Correct 50 ms 13688 KB Output is correct
14 Correct 50 ms 14060 KB Output is correct
15 Correct 51 ms 14064 KB Output is correct
16 Correct 37 ms 11760 KB Output is correct
17 Correct 38 ms 11752 KB Output is correct
18 Correct 40 ms 11512 KB Output is correct
19 Correct 40 ms 11568 KB Output is correct
20 Correct 46 ms 12232 KB Output is correct
21 Correct 41 ms 11992 KB Output is correct
22 Correct 49 ms 14200 KB Output is correct
23 Correct 40 ms 11696 KB Output is correct
24 Correct 44 ms 11696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1792 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 2 ms 1536 KB Output is correct
4 Correct 2 ms 1792 KB Output is correct
5 Correct 2 ms 1792 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 2 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 2 ms 1792 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1808 KB Output is correct
14 Correct 2 ms 1792 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 2 ms 1792 KB Output is correct
17 Correct 2 ms 1792 KB Output is correct
18 Correct 3 ms 1792 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 3 ms 1792 KB Output is correct
21 Correct 2 ms 1792 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 2 ms 1792 KB Output is correct
24 Correct 2 ms 1792 KB Output is correct
25 Correct 2 ms 1792 KB Output is correct
26 Correct 2 ms 1792 KB Output is correct
27 Correct 2 ms 1792 KB Output is correct
28 Correct 2 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 11380 KB Output is correct
2 Correct 46 ms 12756 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 40 ms 11560 KB Output is correct
5 Correct 57 ms 14244 KB Output is correct
6 Correct 54 ms 14128 KB Output is correct
7 Correct 43 ms 13268 KB Output is correct
8 Correct 44 ms 13360 KB Output is correct
9 Correct 53 ms 14028 KB Output is correct
10 Correct 63 ms 14384 KB Output is correct
11 Correct 53 ms 14216 KB Output is correct
12 Correct 62 ms 14248 KB Output is correct
13 Correct 70 ms 14256 KB Output is correct
14 Correct 72 ms 14020 KB Output is correct
15 Correct 54 ms 14116 KB Output is correct
16 Correct 57 ms 14032 KB Output is correct
17 Correct 50 ms 13772 KB Output is correct
18 Correct 57 ms 13772 KB Output is correct
19 Correct 51 ms 13880 KB Output is correct
20 Correct 59 ms 13692 KB Output is correct
21 Correct 62 ms 13800 KB Output is correct
22 Correct 51 ms 13780 KB Output is correct
23 Correct 41 ms 12076 KB Output is correct
24 Correct 40 ms 12092 KB Output is correct
25 Correct 44 ms 12292 KB Output is correct
26 Correct 44 ms 12236 KB Output is correct
27 Correct 61 ms 13012 KB Output is correct
28 Correct 47 ms 12876 KB Output is correct
29 Correct 49 ms 13012 KB Output is correct
30 Correct 46 ms 12984 KB Output is correct
31 Correct 43 ms 12088 KB Output is correct
32 Correct 43 ms 11860 KB Output is correct
33 Correct 44 ms 12284 KB Output is correct
34 Correct 43 ms 12268 KB Output is correct
35 Correct 45 ms 12748 KB Output is correct
36 Correct 48 ms 12956 KB Output is correct
37 Correct 53 ms 12968 KB Output is correct
38 Correct 52 ms 12968 KB Output is correct
39 Correct 49 ms 12960 KB Output is correct
40 Correct 53 ms 12756 KB Output is correct
41 Correct 53 ms 13596 KB Output is correct
42 Correct 69 ms 13260 KB Output is correct
43 Correct 53 ms 13512 KB Output is correct
44 Correct 51 ms 13516 KB Output is correct
45 Correct 57 ms 13496 KB Output is correct
46 Correct 53 ms 13632 KB Output is correct
47 Correct 47 ms 12888 KB Output is correct
48 Correct 48 ms 12628 KB Output is correct
49 Correct 50 ms 12756 KB Output is correct
50 Correct 47 ms 12880 KB Output is correct
51 Correct 40 ms 12372 KB Output is correct
52 Correct 40 ms 12368 KB Output is correct
53 Correct 40 ms 12368 KB Output is correct
54 Correct 41 ms 12244 KB Output is correct
55 Correct 41 ms 12360 KB Output is correct
56 Correct 41 ms 12244 KB Output is correct
57 Correct 44 ms 12116 KB Output is correct
58 Correct 41 ms 12356 KB Output is correct
59 Correct 48 ms 12236 KB Output is correct
60 Correct 44 ms 12172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11560 KB Output is correct
2 Correct 48 ms 12628 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 36 ms 11564 KB Output is correct
5 Correct 56 ms 14136 KB Output is correct
6 Correct 52 ms 14028 KB Output is correct
7 Correct 43 ms 13268 KB Output is correct
8 Correct 44 ms 13268 KB Output is correct
9 Correct 61 ms 14156 KB Output is correct
10 Correct 50 ms 14252 KB Output is correct
11 Correct 56 ms 14128 KB Output is correct
12 Correct 52 ms 14132 KB Output is correct
13 Correct 64 ms 14256 KB Output is correct
14 Correct 52 ms 14264 KB Output is correct
15 Correct 52 ms 14256 KB Output is correct
16 Correct 55 ms 14028 KB Output is correct
17 Correct 52 ms 13772 KB Output is correct
18 Correct 57 ms 13772 KB Output is correct
19 Correct 57 ms 13868 KB Output is correct
20 Correct 59 ms 13868 KB Output is correct
21 Correct 50 ms 13780 KB Output is correct
22 Correct 59 ms 13872 KB Output is correct
23 Correct 43 ms 12084 KB Output is correct
24 Correct 44 ms 11856 KB Output is correct
25 Correct 48 ms 12280 KB Output is correct
26 Correct 44 ms 12472 KB Output is correct
27 Correct 51 ms 12908 KB Output is correct
28 Correct 54 ms 13060 KB Output is correct
29 Correct 55 ms 13036 KB Output is correct
30 Correct 60 ms 13012 KB Output is correct
31 Correct 81 ms 11844 KB Output is correct
32 Correct 50 ms 12084 KB Output is correct
33 Correct 40 ms 12116 KB Output is correct
34 Correct 40 ms 12276 KB Output is correct
35 Correct 46 ms 12948 KB Output is correct
36 Correct 71 ms 12748 KB Output is correct
37 Correct 68 ms 12960 KB Output is correct
38 Correct 54 ms 12764 KB Output is correct
39 Correct 46 ms 12964 KB Output is correct
40 Correct 53 ms 12756 KB Output is correct
41 Correct 58 ms 13508 KB Output is correct
42 Correct 64 ms 13388 KB Output is correct
43 Correct 54 ms 13512 KB Output is correct
44 Correct 51 ms 13396 KB Output is correct
45 Correct 55 ms 13624 KB Output is correct
46 Correct 51 ms 13492 KB Output is correct
47 Correct 44 ms 12868 KB Output is correct
48 Correct 48 ms 12860 KB Output is correct
49 Correct 44 ms 12756 KB Output is correct
50 Correct 55 ms 12756 KB Output is correct
51 Correct 45 ms 12116 KB Output is correct
52 Correct 40 ms 12488 KB Output is correct
53 Correct 46 ms 12492 KB Output is correct
54 Correct 40 ms 12116 KB Output is correct
55 Correct 51 ms 12360 KB Output is correct
56 Correct 44 ms 12368 KB Output is correct
57 Correct 43 ms 12372 KB Output is correct
58 Correct 44 ms 12128 KB Output is correct
59 Correct 43 ms 12368 KB Output is correct
60 Correct 41 ms 12364 KB Output is correct