Submission #590921

# Submission time Handle Problem Language Result Execution time Memory
590921 2022-07-06T14:24:01 Z Namnamseo Stray Cat (JOI20_stray) C++17
100 / 100
45 ms 16868 KB
#include "Anthony.h"
#include <bitset>
#include <vector>
using namespace std;
using vi=vector<int>;

namespace {
const int maxn = int(2e4) + 10;

int n;

struct Edge { int l, r; } ev[maxn];
vector<int> es[maxn];
int lev[maxn];
int col[maxn];

void bfs() {
    static int q[maxn];
    static bitset<maxn> vis;
    int f = 0, t = 1; vis.set(0);
    while (f < t) {
        int x = q[f++];
        for (int ei : es[x]) {
            int y = ev[ei].l + ev[ei].r - x;
            if (vis[y]) continue;
            vis.set(y);
            lev[y] = lev[x]+1;
            q[t++] = y;
        }
    }
}

void Read(int N, int M, vi &U, vi &V) {
    n = N;
    for (int i=0; i<M; ++i) {
        ev[i] = {U[i], V[i]};
        es[U[i]].push_back(i);
        es[V[i]].push_back(i);
    }
}

vi Case1(int N, int M, vi &U, vi &V) {
    Read(N, M, U, V);
    bfs();

    for (int i=0; i<M; ++i) {
        int a = ev[i].l, b = ev[i].r;
        col[i] = min(lev[a], lev[b])%3;
    }
    return vi(col, col+M);
}

const int dict[6] = {0, 1, 1, 0, 0, 1};
void Go(int x, int p, int state) {
    if (es[x].size() == 1u) return;
    if (es[x].size() > 2u) {
        int pc = dict[(state+5)%6];
        for (int ei : es[x]) {
            int y = ev[ei].l + ev[ei].r - x;
            if (y == p) continue;
            col[ei] = pc^1;
            Go(y, x, 1+(pc^1));
        }
        return;
    }

    for (int ei : es[x]) {
        int y = ev[ei].l + ev[ei].r - x;
        if (y == p) continue;
        col[ei] = dict[state];
        Go(y, x, (state+1)%6);
    }
}

vi Case2(int N, int M, vi &U, vi &V) {
    Read(N, M, U, V);
    for (int ei : es[0]) {
        int y = ev[ei].l + ev[ei].r;
        Go(y, 0, 1);
    }
    return vi(col, col+M);
}

}  // namespace

namespace {
}  // namespace

vi Mark(int N, int M, int A, int B, vi U, vi V) {
    if (B == 0)
        return Case1(N, M, U, V);
    else
        return Case2(N, M, U, V);
}
#include "Catherine.h"
#include <cstdio>
#include <vector>
using namespace std;
using vi=vector<int>;

namespace {
int A, B;

int Move1(vi &y) {
    int oc = 0;
    for (int i=0; i<3; ++i) if (y[i]) ++oc;
    if (oc == 1) for (int i=0; i<3; ++i) if (y[i]) return i;

    int tmp = 0;
    for (int i=0; i<3; ++i) if (y[i]) tmp += i;
    tmp += 2;
    tmp *= 2;
    return tmp % 3;
}

}  // namespace

namespace {
int last_move;
vector<int> hist;
bool know;
}  // namespace

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

int Move(vi y) {
    if (B == 0) return Move1(y);

    int last = last_move;
    int which;
    int ec = y[0] + y[1] + (last != -1);

    if (know) {
        if (ec >= 3) which = !last;
        else which = !!y[1];
    } else {
        if (ec >= 3) {
            which = (y[1]+(last==1) == 1);
            if (which == last) which = -1;
            know = true;
        } else if (ec == 1) {
            which = !!(y[1]+(last==1));
            if (which == last) which = -1;
            know = true;
        } else {
            if (last != -1) ++y[last];
            int state = (y[0] == 2) ? 0 :
                      (y[1] == 2) ? 1 : 2;
            if (last != -1) --y[last];
            if (hist.size() == 3u) {
                int t = hist[0]*1000 +
                        hist[1]*100 +
                        hist[2]*10 + state;
                int down_sign = 212022212;
                bool is_down = false;
                for (int i=0; i<6; ++i) {
                    if (down_sign%10000 == t) { is_down = true; break; }
                    down_sign /= 10;
                }
                if (is_down) which = last_move;
                else which = !!y[1];
                if (which == last) which = -1;
                know = true;
            } else {
                hist.push_back(state);
                which = !!y[1];
            }
        }
    }

    if (which != -1) last_move = which;
    return which;
}
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15688 KB Output is correct
2 Correct 1 ms 1020 KB Output is correct
3 Correct 30 ms 14820 KB Output is correct
4 Correct 45 ms 16868 KB Output is correct
5 Correct 44 ms 16856 KB Output is correct
6 Correct 34 ms 15412 KB Output is correct
7 Correct 38 ms 15420 KB Output is correct
8 Correct 41 ms 16208 KB Output is correct
9 Correct 40 ms 16180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15688 KB Output is correct
2 Correct 1 ms 1020 KB Output is correct
3 Correct 30 ms 14820 KB Output is correct
4 Correct 45 ms 16868 KB Output is correct
5 Correct 44 ms 16856 KB Output is correct
6 Correct 34 ms 15412 KB Output is correct
7 Correct 38 ms 15420 KB Output is correct
8 Correct 41 ms 16208 KB Output is correct
9 Correct 40 ms 16180 KB Output is correct
10 Correct 31 ms 13548 KB Output is correct
11 Correct 31 ms 13456 KB Output is correct
12 Correct 34 ms 13416 KB Output is correct
13 Correct 33 ms 13536 KB Output is correct
14 Correct 32 ms 13688 KB Output is correct
15 Correct 36 ms 14172 KB Output is correct
16 Correct 39 ms 16412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13240 KB Output is correct
2 Correct 1 ms 1020 KB Output is correct
3 Correct 28 ms 12808 KB Output is correct
4 Correct 41 ms 14692 KB Output is correct
5 Correct 41 ms 14588 KB Output is correct
6 Correct 32 ms 13236 KB Output is correct
7 Correct 34 ms 13108 KB Output is correct
8 Correct 37 ms 13908 KB Output is correct
9 Correct 40 ms 13880 KB Output is correct
10 Correct 39 ms 13616 KB Output is correct
11 Correct 39 ms 13584 KB Output is correct
12 Correct 35 ms 13672 KB Output is correct
13 Correct 35 ms 13664 KB Output is correct
14 Correct 40 ms 13876 KB Output is correct
15 Correct 40 ms 13892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13240 KB Output is correct
2 Correct 1 ms 1020 KB Output is correct
3 Correct 28 ms 12808 KB Output is correct
4 Correct 41 ms 14692 KB Output is correct
5 Correct 41 ms 14588 KB Output is correct
6 Correct 32 ms 13236 KB Output is correct
7 Correct 34 ms 13108 KB Output is correct
8 Correct 37 ms 13908 KB Output is correct
9 Correct 40 ms 13880 KB Output is correct
10 Correct 39 ms 13616 KB Output is correct
11 Correct 39 ms 13584 KB Output is correct
12 Correct 35 ms 13672 KB Output is correct
13 Correct 35 ms 13664 KB Output is correct
14 Correct 40 ms 13876 KB Output is correct
15 Correct 40 ms 13892 KB Output is correct
16 Correct 28 ms 11704 KB Output is correct
17 Correct 31 ms 11572 KB Output is correct
18 Correct 30 ms 11620 KB Output is correct
19 Correct 30 ms 11624 KB Output is correct
20 Correct 34 ms 12196 KB Output is correct
21 Correct 34 ms 11908 KB Output is correct
22 Correct 44 ms 14032 KB Output is correct
23 Correct 30 ms 11664 KB Output is correct
24 Correct 30 ms 11724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1280 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 2 ms 1284 KB Output is correct
4 Correct 2 ms 1336 KB Output is correct
5 Correct 2 ms 1284 KB Output is correct
6 Correct 2 ms 1336 KB Output is correct
7 Correct 2 ms 1332 KB Output is correct
8 Correct 2 ms 1292 KB Output is correct
9 Correct 2 ms 1292 KB Output is correct
10 Correct 2 ms 1280 KB Output is correct
11 Correct 2 ms 1288 KB Output is correct
12 Correct 2 ms 1284 KB Output is correct
13 Correct 2 ms 1292 KB Output is correct
14 Correct 2 ms 1296 KB Output is correct
15 Correct 1 ms 1328 KB Output is correct
16 Correct 2 ms 1292 KB Output is correct
17 Correct 2 ms 1348 KB Output is correct
18 Correct 2 ms 1328 KB Output is correct
19 Correct 2 ms 1340 KB Output is correct
20 Correct 1 ms 1272 KB Output is correct
21 Correct 2 ms 1284 KB Output is correct
22 Correct 2 ms 1284 KB Output is correct
23 Correct 1 ms 1292 KB Output is correct
24 Correct 1 ms 1284 KB Output is correct
25 Correct 1 ms 1284 KB Output is correct
26 Correct 2 ms 1268 KB Output is correct
27 Correct 1 ms 1284 KB Output is correct
28 Correct 2 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 11160 KB Output is correct
2 Correct 34 ms 12744 KB Output is correct
3 Correct 2 ms 1036 KB Output is correct
4 Correct 26 ms 11328 KB Output is correct
5 Correct 41 ms 14440 KB Output is correct
6 Correct 45 ms 14472 KB Output is correct
7 Correct 36 ms 13556 KB Output is correct
8 Correct 34 ms 13544 KB Output is correct
9 Correct 44 ms 14364 KB Output is correct
10 Correct 41 ms 14428 KB Output is correct
11 Correct 39 ms 14420 KB Output is correct
12 Correct 39 ms 14424 KB Output is correct
13 Correct 38 ms 14436 KB Output is correct
14 Correct 40 ms 14444 KB Output is correct
15 Correct 41 ms 14364 KB Output is correct
16 Correct 40 ms 14440 KB Output is correct
17 Correct 36 ms 14164 KB Output is correct
18 Correct 37 ms 14104 KB Output is correct
19 Correct 36 ms 14112 KB Output is correct
20 Correct 37 ms 14072 KB Output is correct
21 Correct 36 ms 14028 KB Output is correct
22 Correct 36 ms 14148 KB Output is correct
23 Correct 32 ms 11628 KB Output is correct
24 Correct 28 ms 11620 KB Output is correct
25 Correct 31 ms 12084 KB Output is correct
26 Correct 32 ms 12096 KB Output is correct
27 Correct 37 ms 12972 KB Output is correct
28 Correct 37 ms 12880 KB Output is correct
29 Correct 36 ms 12912 KB Output is correct
30 Correct 35 ms 12840 KB Output is correct
31 Correct 31 ms 11592 KB Output is correct
32 Correct 32 ms 11640 KB Output is correct
33 Correct 33 ms 11972 KB Output is correct
34 Correct 31 ms 12072 KB Output is correct
35 Correct 35 ms 12864 KB Output is correct
36 Correct 34 ms 12736 KB Output is correct
37 Correct 34 ms 12860 KB Output is correct
38 Correct 36 ms 12784 KB Output is correct
39 Correct 35 ms 12708 KB Output is correct
40 Correct 38 ms 12840 KB Output is correct
41 Correct 36 ms 13464 KB Output is correct
42 Correct 43 ms 13344 KB Output is correct
43 Correct 40 ms 13432 KB Output is correct
44 Correct 37 ms 13628 KB Output is correct
45 Correct 37 ms 13512 KB Output is correct
46 Correct 39 ms 13512 KB Output is correct
47 Correct 37 ms 12740 KB Output is correct
48 Correct 34 ms 12576 KB Output is correct
49 Correct 36 ms 12420 KB Output is correct
50 Correct 36 ms 12616 KB Output is correct
51 Correct 30 ms 11896 KB Output is correct
52 Correct 30 ms 11896 KB Output is correct
53 Correct 31 ms 11832 KB Output is correct
54 Correct 32 ms 11836 KB Output is correct
55 Correct 30 ms 11916 KB Output is correct
56 Correct 31 ms 11896 KB Output is correct
57 Correct 32 ms 11556 KB Output is correct
58 Correct 32 ms 11656 KB Output is correct
59 Correct 34 ms 11948 KB Output is correct
60 Correct 32 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 11560 KB Output is correct
2 Correct 34 ms 12648 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 26 ms 11336 KB Output is correct
5 Correct 43 ms 14344 KB Output is correct
6 Correct 41 ms 14336 KB Output is correct
7 Correct 35 ms 13488 KB Output is correct
8 Correct 33 ms 13508 KB Output is correct
9 Correct 39 ms 14348 KB Output is correct
10 Correct 40 ms 14460 KB Output is correct
11 Correct 40 ms 14380 KB Output is correct
12 Correct 40 ms 14372 KB Output is correct
13 Correct 40 ms 14396 KB Output is correct
14 Correct 39 ms 14372 KB Output is correct
15 Correct 39 ms 14440 KB Output is correct
16 Correct 40 ms 14420 KB Output is correct
17 Correct 36 ms 14080 KB Output is correct
18 Correct 39 ms 14112 KB Output is correct
19 Correct 36 ms 14104 KB Output is correct
20 Correct 38 ms 14128 KB Output is correct
21 Correct 37 ms 14180 KB Output is correct
22 Correct 38 ms 14132 KB Output is correct
23 Correct 31 ms 11632 KB Output is correct
24 Correct 28 ms 11496 KB Output is correct
25 Correct 32 ms 11972 KB Output is correct
26 Correct 31 ms 12108 KB Output is correct
27 Correct 37 ms 12844 KB Output is correct
28 Correct 35 ms 12852 KB Output is correct
29 Correct 37 ms 12980 KB Output is correct
30 Correct 35 ms 13016 KB Output is correct
31 Correct 28 ms 11564 KB Output is correct
32 Correct 31 ms 11496 KB Output is correct
33 Correct 32 ms 12076 KB Output is correct
34 Correct 31 ms 12004 KB Output is correct
35 Correct 35 ms 12884 KB Output is correct
36 Correct 35 ms 12796 KB Output is correct
37 Correct 35 ms 12748 KB Output is correct
38 Correct 37 ms 12748 KB Output is correct
39 Correct 34 ms 12768 KB Output is correct
40 Correct 39 ms 12824 KB Output is correct
41 Correct 40 ms 13428 KB Output is correct
42 Correct 38 ms 13380 KB Output is correct
43 Correct 37 ms 13424 KB Output is correct
44 Correct 38 ms 13496 KB Output is correct
45 Correct 37 ms 13416 KB Output is correct
46 Correct 36 ms 13448 KB Output is correct
47 Correct 37 ms 12508 KB Output is correct
48 Correct 36 ms 12592 KB Output is correct
49 Correct 33 ms 12556 KB Output is correct
50 Correct 33 ms 12672 KB Output is correct
51 Correct 32 ms 11872 KB Output is correct
52 Correct 32 ms 11824 KB Output is correct
53 Correct 31 ms 11804 KB Output is correct
54 Correct 32 ms 11848 KB Output is correct
55 Correct 31 ms 11864 KB Output is correct
56 Correct 31 ms 11800 KB Output is correct
57 Correct 31 ms 11744 KB Output is correct
58 Correct 32 ms 11764 KB Output is correct
59 Correct 30 ms 12008 KB Output is correct
60 Correct 31 ms 11948 KB Output is correct