Submission #590920

# Submission time Handle Problem Language Result Execution time Memory
590920 2022-07-06T14:23:27 Z Namnamseo Stray Cat (JOI20_stray) C++17
15 / 100
55 ms 17160 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) {
    printf("Go(x=%d, p=%d, state=%d\n", x, p, 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);
    }
    for (int i=0; i<M; ++i) printf("col[%d-%d] = %d\n", ev[i].l, ev[i].r, col[i]);
    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 16008 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 34 ms 15420 KB Output is correct
4 Correct 55 ms 17160 KB Output is correct
5 Correct 46 ms 17108 KB Output is correct
6 Correct 35 ms 15968 KB Output is correct
7 Correct 39 ms 15864 KB Output is correct
8 Correct 45 ms 16512 KB Output is correct
9 Correct 46 ms 16500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 16008 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 34 ms 15420 KB Output is correct
4 Correct 55 ms 17160 KB Output is correct
5 Correct 46 ms 17108 KB Output is correct
6 Correct 35 ms 15968 KB Output is correct
7 Correct 39 ms 15864 KB Output is correct
8 Correct 45 ms 16512 KB Output is correct
9 Correct 46 ms 16500 KB Output is correct
10 Correct 37 ms 14008 KB Output is correct
11 Correct 35 ms 13844 KB Output is correct
12 Correct 35 ms 13900 KB Output is correct
13 Correct 32 ms 13992 KB Output is correct
14 Correct 33 ms 14124 KB Output is correct
15 Correct 37 ms 14396 KB Output is correct
16 Correct 41 ms 16680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13600 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 30 ms 13184 KB Output is correct
4 Correct 49 ms 14988 KB Output is correct
5 Correct 41 ms 14928 KB Output is correct
6 Correct 32 ms 13680 KB Output is correct
7 Correct 35 ms 13684 KB Output is correct
8 Correct 43 ms 14204 KB Output is correct
9 Correct 41 ms 14284 KB Output is correct
10 Correct 37 ms 14008 KB Output is correct
11 Correct 37 ms 13928 KB Output is correct
12 Correct 38 ms 13940 KB Output is correct
13 Correct 37 ms 14084 KB Output is correct
14 Correct 49 ms 14184 KB Output is correct
15 Correct 52 ms 14296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13600 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 30 ms 13184 KB Output is correct
4 Correct 49 ms 14988 KB Output is correct
5 Correct 41 ms 14928 KB Output is correct
6 Correct 32 ms 13680 KB Output is correct
7 Correct 35 ms 13684 KB Output is correct
8 Correct 43 ms 14204 KB Output is correct
9 Correct 41 ms 14284 KB Output is correct
10 Correct 37 ms 14008 KB Output is correct
11 Correct 37 ms 13928 KB Output is correct
12 Correct 38 ms 13940 KB Output is correct
13 Correct 37 ms 14084 KB Output is correct
14 Correct 49 ms 14184 KB Output is correct
15 Correct 52 ms 14296 KB Output is correct
16 Correct 31 ms 12148 KB Output is correct
17 Correct 28 ms 12092 KB Output is correct
18 Correct 32 ms 12092 KB Output is correct
19 Correct 30 ms 11976 KB Output is correct
20 Correct 37 ms 12544 KB Output is correct
21 Correct 35 ms 12280 KB Output is correct
22 Correct 40 ms 14468 KB Output is correct
23 Correct 35 ms 12056 KB Output is correct
24 Correct 33 ms 12156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1048 KB Program didn't exit properly, or you printed something to stdout.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 5236 KB Program didn't exit properly, or you printed something to stdout.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5140 KB Program didn't exit properly, or you printed something to stdout.
2 Halted 0 ms 0 KB -