제출 #841541

#제출 시각아이디문제언어결과실행 시간메모리
841541model_codeRobot Contest (IOI23_robot)C++17
59 / 100
167 ms7932 KiB
// partially_correct/8colors_no_cleanup.cpp

/* colors.txt:
#ffffff 0
#005ca5 1
#ff0000 a
#ff5500 b
#ffff00 c
#005500 a
#00ff00 b
#aaff7f c
*/


#include "robot.h"

int dist(int x)
{
    return x < 2 ? 0 : (x + 1) % 3 + 1;
}

int state(int x)
{
    return (x + 1) / 3;
}

int color(int dist, int state)
{
    return (dist + 2) % 3 + state * 3 - 1;
}

bool isnext(int a, int b)
{
    if (a < 2 || b < 2)
        return false;
    return (a + 1) % 3 == b % 3;
}

char move[5] = {'_', 'W', 'S', 'E', 'N'};

void get_move(std::vector<int> S, int &Z, char &A)
{
    bool is_start = S[1] == -2 && S[4] == -2;
    bool is_end = S[2] == -2 && S[3] == -2;
    bool is_path = is_end;
    for (int i = 1; i <= 4; i++)
    {
        if (S[i] == 1)
        {
            is_path = true;
        }
    }
    if (is_path)
    {
        for (int i = 1; i <= 4; i++)
        {
            if (state(S[i]) == 2)
            {
                Z = 1;
                A = move[i];
                return;
            }
        }
        if (is_start)
        {
            Z = 1;
            A = 'T';
            return;
        }
    }
    if (S[0] == 0)
    {
        for (int i = 1; i <= 4; i++)
        {
            if (state(S[i]) == 2)
            {
                Z = color(dist(S[i]) - 1, 1);
                A = move[i];
                return;
            }
        }
        if (is_start)
        {
            Z = color(1, 1);
            A = 'H';
        }
        return;
    }
    for (int i = 1; i <= 4; i++)
    {
        if (S[i] == 0)
        {
            Z = color(dist(S[0]), 2);
            A = move[i];
            return;
        }
        else if (isnext(S[0], S[i]))
        {
            Z = color(dist(S[0]), 2);
            A = move[i];
            return;
        }
    }
    Z = color(dist(S[0]) + 1, 1);
    A = 'H';
    for (int i = 1; i <= 4; i++)
    {
        if (state(S[i]) == 2)
        {
            A = move[i];
        }
    }
}

void program_pulibot()
{
    std::vector<int> S(5);
    #define LOOP(i) for (S[i] = -2; S[i] < 8; S[i]++)
    LOOP(0) LOOP(1) LOOP(2) LOOP(3) LOOP(4)
    {
        int Z = -1;
        char A;
        get_move(S, Z, A);
        if (Z != -1)
            set_instruction(S, Z, A);
    }
}
#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...