제출 #1061661

#제출 시각아이디문제언어결과실행 시간메모리
1061661Hanksburger길고양이 (JOI20_stray)C++17
100 / 100
56 ms16764 KiB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
int d[20005], c[20005], e[20005], p[20005];
vector<int> adj[20005];
queue<int> q;
void dfs(int u)
{
    for (int v:adj[u])
    {
        if (v==p[u])
            continue;
        p[v]=u;
        c[v]=!c[u];
        if (adj[v].size()>=3)
            dfs(v);
        else
            q.push(v);
    }
}
void dfs2(int u)
{
    for (int v:adj[u])
    {
        if (v==p[u])
            continue;
        p[v]=u;
        e[v]=(e[u]+1)%6;
        if (e[v]==2 || e[v]==4 || e[v]==5)
            c[v]=1;
        if (adj[v].size()>=3)
            q.push(v);
        else
            dfs2(v);
    }
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V)
{
    for (int i=0; i<M; i++)
    {
        adj[U[i]].push_back(V[i]);
        adj[V[i]].push_back(U[i]);
    }
    if (A>2)
    {
        d[0]=1;
        q.push(0);
        while (!q.empty())
        {
            int u=q.front();
            q.pop();
            for (int v:adj[u])
            {
                if (!d[v])
                {
                    d[v]=d[u]+1;
                    q.push(v);
                }
            }
        }
        vector<int> ans;
        for (int i=0; i<M; i++)
            ans.push_back(min(d[U[i]], d[V[i]])%3);
        return ans;
    }
    q.push(0);
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        if ((u==0 && adj[u].size()>=2) || adj[u].size()>=3)
            dfs(u);
        else
        {
            if (c[u])
                e[u]=5;
            dfs2(u);
        }
    }
    vector<int> ans;
    for (int i=0; i<M; i++)
    {
        if (U[i]==p[V[i]])
            ans.push_back(c[V[i]]);
        else
            ans.push_back(c[U[i]]);
        //cout << ans[i] << ' ';
    }
    //cout << '\n';
    return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
int a, pre=2, ok;
vector<int> vec;
void Init(int A, int B)
{
    a=A;
}
int Move(vector<int> y)
{
    if (a>2)
    {
        if (y[0] && !y[2])
            return 0;
        else if (y[1] && !y[0])
            return 1;
        else
            return 2;
    }
    if (pre==2)
    {
        if (y[0]+y[1]==1 || y[0]+y[1]>=3)
        {
            ok=1;
            if (y[0]==1)
            {
                pre=0;
                return 0;
            }
            else
            {
                pre=1;
                return 1;
            }
        }
        else
        {
            if (y[0]==2)
            {
                vec.push_back(0);
                //cout << "vec push " << vec[0] << '\n';
                pre=0;
                return 0;
            }
            else if (y[1]==2)
            {
                vec.push_back(1);
                //cout << "vec push " << vec[0] << '\n';
                pre=1;
                return 1;
            }
            else
            {
                vec.push_back(1);
                //cout << "vec push " << vec[0] << '\n';
                pre=0;
                return 0;
            }
        }
    }
    else
    {
        if (y[0]+y[1]==0)
        {
            //cout << "im here 1\n";
            ok=1;
            return -1;
        }
        else if (y[0]+y[1]>=2)
        {
            //cout << "im here 2\n";
            ok=1;
            if (!y[0] || !y[1])
                return -1;
            y[pre]++;
            if (y[0]==1)
            {
                pre=0;
                return 0;
            }
            else
            {
                pre=1;
                return 1;
            }
        }
        else if (ok)
        {
            //cout << "im here 3\n";
            if (y[0]==1)
            {
                pre=0;
                return 0;
            }
            else
            {
                pre=1;
                return 1;
            }
        }
        else
        {
            vec.push_back(pre);
            //cout << "vec push " << pre << '\n';
            if (vec.size()==4)
            {
                ok=1;
                if (y[0])
                    vec.push_back(0);
                else
                    vec.push_back(1);
                if ((vec[0]==0 && vec[1]==0 && vec[2]==1 && vec[3]==0 && vec[4]==1) ||
                    (vec[0]==0 && vec[1]==1 && vec[2]==0 && vec[3]==1 && vec[4]==1) ||
                    (vec[0]==1 && vec[1]==0 && vec[2]==1 && vec[3]==1 && vec[4]==0) ||
                    (vec[0]==0 && vec[1]==1 && vec[2]==1 && vec[3]==0 && vec[4]==0) ||
                    (vec[0]==1 && vec[1]==1 && vec[2]==0 && vec[3]==0 && vec[4]==1) ||
                    (vec[0]==1 && vec[1]==0 && vec[2]==0 && vec[3]==1 && vec[4]==0))
                    return -1;
                else
                {
                    if (y[0])
                    {
                        pre=0;
                        return 0;
                    }
                    else
                    {
                        pre=1;
                        return 1;
                    }
                }
            }
            else
            {
                if (y[0])
                {
                    pre=0;
                    return 0;
                }
                else
                {
                    pre=1;
                    return 1;
                }
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...