Submission #260719

# Submission time Handle Problem Language Result Execution time Memory
260719 2020-08-10T19:12:33 Z Kastanda Stray Cat (JOI20_stray) C++14
15 / 100
75 ms 20416 KB
// M
#include<bits/stdc++.h>
#include "Anthony.h"
using namespace std;

const int N = 21234;

int D[N];
vector < int > Adj[N];
vector < pair < int , int > > Ad[N];

vector < int > Sub(int n, int m, int A, int B, vector < int > U, vector < int > V)
{
        assert(B == 0 && A >= 3);

        for (int i = 0; i < m; i ++)
                Adj[U[i]].push_back(V[i]), Adj[V[i]].push_back(U[i]);

        memset(D, -1, sizeof(D));
        queue < int > qu;
        qu.push(0); D[0] = 0;
        while (qu.size())
        {
                int v = qu.front();
                qu.pop();
                for (int u : Adj[v])
                        if (D[u] == -1)
                                D[u] = D[v] + 1, qu.push(u);
        }

        vector < int > C(m, 0);
        for (int i = 0; i < m; i ++)
        {
                int d = min(D[V[i]], D[U[i]]);
                C[i] = d % 3;
        }
        return C;
}

int C[N];
int gx[] = {1, 1, 0, 0, 1, 0};
vector < int > RS;

void DFS(int v, int p, int cc = 0)
{
        for (int i = 0; i < (int)Ad[v].size(); i ++)
                if (Ad[v][i].first == p)
                        Ad[v].erase(Ad[v].begin() + i);
        if (!Ad[v].size())
                return ;

        if (Adj[v].size() > 1)
        {
                for (auto u : Ad[v])
                        C[u.first] = !C[v], RS[u.second] = !C[v], DFS(u.first, v, 0);
                return ;
        }

        if (Adj[v].size() == 1)
        {
                C[Ad[v][0].first] = gx[cc];
                RS[Ad[v][0].second] = gx[cc];
                DFS(Ad[v][0].first, v, (cc + 1) % 6);
                return ;
        }
}

vector < int > Mark(int n, int m, int A, int B, vector < int > U, vector < int > V)
{
        if (B == 0)
                return Sub(n, m, A, B, U, V);

        assert(A == 2);
        for (int i = 0; i < m; i ++)
                Ad[U[i]].push_back({V[i], i}), Ad[V[i]].push_back({U[i], i});

        RS = vector < int >(m, 0);
        DFS(0, -1);
        return RS;

}
// M
#include<bits/stdc++.h>
#define prev lolololol
#include "Catherine.h"
using namespace std;

const int N = 21234;

int cA, cB;
int prev = -1, Found = 0;

vector < int > Cur;
vector < vector < int > > vec;

void Init(int A, int B)
{
        cA = A;
        cB = B;
        prev = -1;
        Found = 0;

        vec.push_back({1, 1, 0, 1, 1, 0});
        vec.push_back({1, 1, 1, 0, 1, 1});
        vec.push_back({1, 1, 1, 1, 0, 0});
        vec.push_back({0, 2, 1, 0, 0, 1});
        vec.push_back({1, 1, 0, 0, 1, 0});
        vec.push_back({2, 0, 0, 1, 0, 1});
}

int Move2(vector < int > Freq)
{
        assert(cB == 0 && cA >= 3);

        int c = 0;
        for (int a : Freq)
                if (a) c ++;
        if (c == 1 && Freq[0])
                return 0;
        if (c == 1 && Freq[1])
                return 1;
        if (c == 1 && Freq[2])
                return 2;

        assert(c == 2);
        if (Freq[0] && Freq[1])
                return 0;
        if (Freq[0])
                return 2;
        return 1;
}

int Move(vector < int > Freq)
{
        if (cB == 0)
                return Move2(Freq);

        assert(cA == 2);

        int dg = Freq[0] + Freq[1];
        if (prev != -1) dg ++;
        assert(dg);

        if (dg == 1)
        {
                Found = 1;
                if (prev != -1)
                        return -1;
                prev = Freq[0] ? 0 : 1;
                return prev;
        }

        if (dg > 2)
        {
                Found = 1;
                if (prev != -1 && Freq[prev] == 0)
                        return -1;
                if (prev != 0 && Freq[0] == 1)
                        return prev = 0;
                assert(prev != 1 && Freq[1] == 1);
                return prev = 1;
        }

        if (Found)
                return prev = (Freq[0] ? 0 : 1);

        if (!Cur.size())
        {
                Cur.push_back(Freq[0]);
                Cur.push_back(Freq[1]);
                Cur.push_back(Freq[1] > 0);
                return prev = Freq[1] ? 1 : 0;
        }

        Cur.push_back(Freq[1] == 1);
        if (Cur.size() < 6)
                return prev = Freq[1] == 1;

        assert(Cur.size() == 6);
        bool ff = 0;
        for (auto v : vec)
                ff |= Cur == v;
        if (Cur[2] == 1 && Cur[3] == 1 && Cur[4] == 0 && Cur[5] == 0)
                ff = 1;
        Found = 1;
        if (ff)
                return -1;
        return prev = Freq[1];
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 16812 KB Output is correct
2 Correct 1 ms 2816 KB Output is correct
3 Correct 41 ms 16148 KB Output is correct
4 Correct 66 ms 17996 KB Output is correct
5 Correct 65 ms 17952 KB Output is correct
6 Correct 52 ms 16528 KB Output is correct
7 Correct 65 ms 16536 KB Output is correct
8 Correct 75 ms 17356 KB Output is correct
9 Correct 65 ms 17236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 16812 KB Output is correct
2 Correct 1 ms 2816 KB Output is correct
3 Correct 41 ms 16148 KB Output is correct
4 Correct 66 ms 17996 KB Output is correct
5 Correct 65 ms 17952 KB Output is correct
6 Correct 52 ms 16528 KB Output is correct
7 Correct 65 ms 16536 KB Output is correct
8 Correct 75 ms 17356 KB Output is correct
9 Correct 65 ms 17236 KB Output is correct
10 Correct 46 ms 14408 KB Output is correct
11 Correct 46 ms 14536 KB Output is correct
12 Correct 46 ms 14728 KB Output is correct
13 Correct 46 ms 14576 KB Output is correct
14 Correct 54 ms 14860 KB Output is correct
15 Correct 57 ms 15244 KB Output is correct
16 Correct 65 ms 17592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 14288 KB Output is correct
2 Correct 1 ms 2816 KB Output is correct
3 Correct 40 ms 13752 KB Output is correct
4 Correct 61 ms 15572 KB Output is correct
5 Correct 63 ms 15844 KB Output is correct
6 Correct 49 ms 14364 KB Output is correct
7 Correct 47 ms 14360 KB Output is correct
8 Correct 55 ms 15060 KB Output is correct
9 Correct 56 ms 15052 KB Output is correct
10 Correct 53 ms 14892 KB Output is correct
11 Correct 52 ms 14804 KB Output is correct
12 Correct 55 ms 14668 KB Output is correct
13 Correct 51 ms 14856 KB Output is correct
14 Correct 59 ms 15188 KB Output is correct
15 Correct 57 ms 14924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 14288 KB Output is correct
2 Correct 1 ms 2816 KB Output is correct
3 Correct 40 ms 13752 KB Output is correct
4 Correct 61 ms 15572 KB Output is correct
5 Correct 63 ms 15844 KB Output is correct
6 Correct 49 ms 14364 KB Output is correct
7 Correct 47 ms 14360 KB Output is correct
8 Correct 55 ms 15060 KB Output is correct
9 Correct 56 ms 15052 KB Output is correct
10 Correct 53 ms 14892 KB Output is correct
11 Correct 52 ms 14804 KB Output is correct
12 Correct 55 ms 14668 KB Output is correct
13 Correct 51 ms 14856 KB Output is correct
14 Correct 59 ms 15188 KB Output is correct
15 Correct 57 ms 14924 KB Output is correct
16 Correct 46 ms 12696 KB Output is correct
17 Correct 51 ms 12860 KB Output is correct
18 Correct 49 ms 12656 KB Output is correct
19 Correct 46 ms 12672 KB Output is correct
20 Correct 59 ms 13328 KB Output is correct
21 Correct 46 ms 13036 KB Output is correct
22 Correct 57 ms 15320 KB Output is correct
23 Correct 44 ms 12924 KB Output is correct
24 Correct 46 ms 12828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2624 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 20416 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 20264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -